﻿
$(function(){

getSessionValue();
  addCookie($("#floors_id").val(),$("#floor_name").val(),$("#avg_price").val());
$.post("../user/userTeamBuy.do?d=firstLoadUserTeamBuy&floors_id="+document.getElementById("floors_id").value,{},function(xml){
		$("#userTeamBuyDiv").html(xml);
	});
	$.post("../floor/score.do?d=toScoreView2&floor_id="+document.getElementById("floors_id").value,{},function(xml){
		$("#pingji").html(xml);
	////////////////////////////////////////////
	$("div[id=pingji]").find("img").hover(
	function (){
		var thiz = $( this );
		saveStatus(thiz);
		thiz.prevAll().andSelf().attr("src",star_1);
		thiz.nextAll().attr("src",star_0);
	},
	function(){
		var thiz = $( this );
		var imgs = thiz.parent().find(" img ");
		imgs.each(function(i){
			 imgs.eq(i).attr("src",old_star_arr[i]);
		});
	}
	);
	//////////////////////////
	
	$("div[id=pingji]").find("img").bind("click",function (){
	var thiz = $( this );
	changeImgs(thiz);
	var uri = "../floor/score.do?d=getScoreJSON"; 
	var item = thiz.parent().find("i:first").attr("item");
	var itemF=3;
	if(item==1){
		itemF=3;
	}else if(item==2){
		itemF=2;
	}else if(item==3){
		itemF=1.6;
	}else if(item==4){
		itemF=1.6;
	}else if(item==5){
		itemF=4;
	}else if(item==6){
		itemF=2.4;
	}else if(item==7){
		itemF=3;
	}else if(item==8){
		itemF=2;
	}else if(item==9){
		itemF=2.4;
	}else if(item==10){
		itemF=2;
	}
	var each_score = ($(this).parent().find(" img ").index(thiz)+1) *itemF;
	var dangqianf=document.getElementById("viewFloors_pingfen_dangqian").innerText;
	var dangqianf_int= parseFloat(dangqianf);
	if(dangqianf_int>=120 || dangqianf_int+each_score >120 ){
		alert("评分失败，当前分数达到上限！");return;
	}
	document.getElementById("viewFloors_pingfen_dangqian").innerText=(dangqianf_int+each_score);
	var floor_id = $("input[name=floors_id]").val();
	//alert(item+"  "+floor_id+"  "+each_score+"  ");
	$.getJSON(uri,{each_score:each_score,item:item,floor_id:floor_id},function(json){
		//alert(thiz.find(" ~ i :first > font").html());
	//	alert(json.person_num);
		if(json.person_num == -1){
			alert("请不要重复评分");return;
		}else{
			thiz.find(" ~ i :first > font").html(json.person_num);
			thiz.find(" ~ i :last > font").html(json.avg);
		}
		
	});
	if(dangqianf_int>=120 || dangqianf_int+each_score >120 ){
		alert("评分失败，当前分数达到上限！");return;
	}
	
	document.getElementById("viewFloors_pingfen_dangqian").innerText=(dangqianf_int+each_score);
	});
	
	///////////////////////
	});
});

$(function() {
      $('.tt a').lightBox();
      $('.xgt_xx').lightBox();
});
function changeImgs(thiz){
	thiz.prevAll().andSelf().each(function(i){
		thiss = $( this );
		thiss.attr("src",star);
	});
	thiz.nextAll().attr("src",star_0);
	saveStatus(thiz);
};
function saveStatus(thiz){
	var imgs = thiz.parent().find(" img ");
	imgs.each(function(i){
		old_star_arr[i] = imgs.eq(i).attr("src");
	});
}
var old_star_arr = new Array();
var star_1 = "../images/star_1.gif";//little color
var star = "../images/star.gif";//all color
var star_0 = "../images/star_0.gif";//empty color


function generateValidateImage(){
	document.getElementById("validateImg").src = "subject.do?d=getValidateImage&rnd="+Math.random();
}
function submitUserTeamBuy(){
	var floor_id = $("#floor_id");
		if(floor_id.val()==null || floor_id.val()==""){
		document.getElementById("floor_id").value=document.getElementById("floors_id").value;}
	var user_name = $("#user_name");
	var user_type = $("#user_type");
	var real_name = $("#real_name");
	var sex = $("input[name=sex][checked]");
	var age = $("#age");
	var mobile = $("#mobile");
	var e_mail = $("#e_mail");
	var comm_addr = $("#comm_addr");
	var buy_goal = $("#buy_goal");
	var buy_area = $("#buy_area");
	var room_type = $("#room_type");
	var remark = $("#remark");
	var floor_id = $("#floor_id");
	var decide_buy = $("input[name=decide_buy][checked]");
	var flag = $("#userTeamBuyForm1").valid();
	if(!flag) return;
	$.post("../user/userTeamBuy.do?d=saveUserTeamBuy",{
			floor_id:floor_id.val(),
			user_name:user_name.val(),
			user_type:user_type.val(),
			real_name:real_name.val(),
			sex:sex.val(),
			age:age.val(),
			mobile:mobile.val(),
			e_mail:e_mail.val(),
			comm_addr:comm_addr.val(),
			buy_goal:buy_goal.val(),
			buy_area:buy_area.val(),
			room_type:room_type.val(),
			remark:remark.val(),
			floor_id:floor_id.val(),
			decide_buy:decide_buy.val()
			},function(xml){
		if(xml == -1){
			alert("参加团购失败！");
		}else{
			alert("参加团购成功！");
			$("#userTeamBuyDiv").html(xml);
			getComment2();
		}
	});
	
}
//动态获取评论方法 author wxm.
function getComment2(){
	$.post("../floor/floors.do?d=getCommentForAJAX&floors_id="+document.getElementById("floors_id").value,{},function(xml){
	var commentConntent="";
	
		//alert(xml);
	if(xml!=null && xml!=""){
		var fC=xml.split("^#");
		var floors_id=document.getElementById("floors_id").value;
		var floor_name_url=document.getElementById("floor_name_url").value;
		document.getElementById("reDianPingLun").innerHTML="访问：<span>"+fC[3]+"</span>&nbsp;<a style='color:#000;' target=_blank href='http://comment.funba.qdfdc.com/comment/comment_funba.htm?channelid=1&aid="+floors_id+"&type_url=&type=1&subject="+floor_name_url+"' >网评：<span>"+fC[2]+"</span></a>";
		if (fC[1]!=null && fC[1]!="" && fC[1]!="null" ){
		document.getElementById("zuiXinPingLun").innerHTML="最新评论："+fC[1].substring(0,11);
		}if(fC[4]!=null && fC[4]!="" && fC[4]!="null"){
			document.getElementById("pinjizhonghepingfen").innerHTML=fC[4];
		}if(fC[5]!=null && fC[5]!="" && fC[5]!="null"){
			document.getElementById("pingfen_zpfrs_lable").innerHTML=fC[5];//动态评分
		}if(fC[6]!=null && fC[6]!="" && fC[6]!="null"){
			document.getElementById("floorsTuanGouCount").innerHTML=fC[6];//动态团购
			addCookieUch();
		}if(fC[7]!=null && fC[7]!="" && fC[7]!="null"){
			document.getElementById("zuiJinGengXinShiJian").innerHTML="最近更新时间："+fC[7];//动态团购
		}if(fC[8]!=null && fC[8]!="" && fC[8]!="null"){
			document.getElementById("guanzhudu_span").innerHTML=fC[8];
		}
		var commentDiv=document.getElementById("FloorCommentDiv");
		var commentlist=fC[0].split("$#");
			for (var i = 0; i < commentlist.length - 1; i++) {
				var comment=commentlist[i].split("%#");
				commentConntent=commentConntent+'<li><h5><span>'+(fC[2]--)+'楼</span><a target="_blank"  href="http://comment.funba.qdfdc.com/comment/comment_funba.htm?channelid=1&aid=$'+document.getElementById("floors_id").value+'&type_url=&type=1&subject='+document.getElementById("floor_name_url").value+'" >房吧网友：&nbsp;&nbsp;&nbsp;&nbsp;'+comment[1]+'</a></h5><p>'+comment[2]+'</p></li>';
			}
		}else{
			commentConntent='<li><span>暂无评论！</span></li>';
		}
		commentConntent=commentConntent+'<p  class="a_right"><a  target="_blank" href="http://comment.funba.qdfdc.com/comment/comment_funba.htm?channelid=1&aid='+document.getElementById("floors_id").value+'&type_url=&type=1&subject='+document.getElementById("floor_name_url").value+'">[更多..]</a></p>';
		$("#FloorCommentDiv").html(commentConntent);
	});
}
//动态获取评论方法 author wxm.
function getDianPing(){
	$.post("../floor/floors.do?d=getDianPingForAJAX&floors_id="+document.getElementById("floors_id").value,{},function(xml){
	var commentConntent="";
	if(xml!=null && xml!=""){
		var fC=xml;
		var commentlist=fC.split("$#");
			for (var i = 0; i < commentlist.length - 1; i++) {
			var comment=commentlist[i].split("%#");
				commentConntent=commentConntent+'<li><h5><a target="_blank"  href="http://comment.funba.qdfdc.com/comment/comment_funba.htm?channelid=1&aid=$'+document.getElementById("floors_id").value+'&type_url=&type=1&subject='+document.getElementById("floor_name_url").value+'" >楼盘专家：&nbsp;&nbsp;&nbsp;&nbsp;'+comment[1]+'</a></h5><p>'+comment[2]+'</p></li>';
			}
		}else{
			commentConntent='<li><span class="font_black4">暂无专家点评！</span></li>';
		}
		$("#FloorDianPingDiv").html(commentConntent);
	});
}
function getFloorPic(){
	$.post("../floor/floors.do?d=getFloorPicForAJAX&floors_id="+document.getElementById("floors_id").value,{},function(xml){
		var picContent="";
		var hxtContent="";
		var sjtContent="";
		var xgtContent="";
		if(xml!=null && xml!=""){
			var pic=xml.split("$$");
			if(pic[0]!="" && pic[0]!=null){
				var hxt=pic[0].split("$#");
				for (var i = 0; i <hxt.length - 1; i++) {
					var h=hxt[i].split("%#");
					if(h[2]==null || h[2]=="" || h[2]==0.0){
					h[2]="不详";
					}
					hxtContent+='<li class="xmimg tt"><a  target="_blank" href="http://funba.qdfdc.com/upload/old/'+h[0]+'" ><img  src="http://funba.qdfdc.com/upload/small/'+h[0]+'"  /></a>';
					hxtContent+='<p>户型:'+h[1]+'</p>';
					hxtContent+='<p><span>建筑面积：<b>'+h[2]+'</b>㎡</span></p>';
					var ms=h[3];
					if(ms!=null||ms.length>14){
						ms=ms.substring(0,14);
					}
					hxtContent+='<p>'+ms+'</li>';
					
				}
			}else{
				hxtContent+='<center>暂无户型图信息...</center>';
			}	
				$("#FloorPicHXT").html(hxtContent);
			if(pic[1]!=""&&pic[1]!=null){
				var sjt=pic[1].split("$#");
				for (var i = 0; i <sjt.length - 1; i++) {
					var s=sjt[i].split("%#");
					sjtContent+='<li class="xmimg tt"><a href="http://funba.qdfdc.com/upload/old/'+s[0]+'"><img src="http://funba.qdfdc.com/upload/small/'+s[0]+'"/></a></li>';
				}
			}else{
				sjtContent+='<center>暂无实景图信息...</center>';
			}
				$("#FloorPicSJT").html(sjtContent);
				
			if(pic[2]!=""&&pic[2]!=null){
				var xgt=pic[2].split("$#");
				for (var i = 0; i <xgt.length - 1; i++) {
					var s=xgt[i].split("%#");
					xgtContent+='<li class="xmimg tt"><a href="http://funba.qdfdc.com/upload/old/'+s[0]+'"><img src="http://funba.qdfdc.com/upload/small/'+s[0]+'"/></a>';
					xgtContent+='<p>'+s[1].substring(0,10)+'</p></li>';
				}
			}else{
				xgtContent+='<center>暂无效果图信息...</center>';
			}
				$("#FloorPicXGT").html(xgtContent);
		}
		$('.tt a').lightBox();
      	$('.xgt_xx').lightBox();
	});
}
/*
//动态获取新闻方法 author wxm.
function getNews(){
	$.post("../floor/floors.do?d=getNewsForAJAX&floors_id="+document.getElementById("floors_id").value,{},function(xml){
	var newsConntent="";
		if(xml!=null && xml!=""){
		var newsDiv=document.getElementById("FloorNewsDiv");
		var newslist=xml.split("&#");
			for (var i = 0; i < newslist.length - 1; i++) {
				var news=newslist[i].split("%#");
					newsConntent=newsConntent+'<div class="xgnews">'+
								'<div class="xgtitle">'+
									'<a target="_blank" href="'+news[0]+'" class="font_blue1">'+news[1]+'</a>'+
								'</div>'+
								'<div class="xgtext">'+
								'<font class="font_black5">'+news[2]+
								'</font>'+
								'</div>'+
								'<div class="xgtime font_orange1">'+news[3]+'</div>'+
							'</div>';
				}
		}else{
			newsConntent='<li><span class="font_black4">暂无评论！</span></li>';
		}
		newsConntent=newsConntent+'<div class="more"><a target="_blank" href="http://so.sdfdc.com" class="font_blue1">[更多..]</a></div>';
		newsDiv.innerHTML=newsConntent;
	});
}*/
//动态获取新闻方法 author wxm.
function getNews2(){
	$.post("../floor/floors.do?d=getNewsForAJAX&floors_id="+document.getElementById("floors_id").value,{},function(xml){
	var newsConntent="";	
		if(xml!=null && xml!=""){
		var newslist=xml.split("&#");
			for (var i = 0; i < newslist.length - 1; i++) {
				var news=newslist[i].split("%#");
				if(news[1]==null|| news[2]==null || news[1]=="undefined" || news[2]=='undefined'){continue;  }
					newsConntent+='<li><h5><a target="_blank" href="'+news[0]+'" >'+news[1]+'</a></h5><p>'+news[2]+'</p></li>';				
				}
		}else{
			newsConntent='<li><span>暂无新闻</span></li>';
		}
		$("#FloorNewsDiv").html(newsConntent);
	});
}
//动态获取二手房方法 author wxm.
function getErShou(){
	var addr=$("#floor_name_url").val();
	var area_code=$("#area_code").val();
	var str="";
	var url="";
	if(area_code.indexOf("016001") >= 0) url = "esf.jn.sdfdc";
	else if(area_code.indexOf("016002") >= 0) url = "esf.lc.sdfdc";
	else if(area_code.indexOf("016003") >= 0) url = "esf.dz.sdfdc";
	else if(area_code.indexOf("016004") >= 0) url = "esf.dy.sdfdc";
	else if(area_code.indexOf("016005") >= 0) url = "esf.zb.sdfdc";
	else if(area_code.indexOf("016005") >= 0) url = "esf.zbfdc";
	else if(area_code.indexOf("016006") >= 0) url = "esf.wf.sdfdc";
	else if(area_code.indexOf("016007") >= 0) url = "esf.yt.sdfdc";
	else if(area_code.indexOf("016008") >= 0) url = "esf.wh.sdfdc";
	else if(area_code.indexOf("016009") >= 0) url = "esf.qdfdc";
	else if(area_code.indexOf("016010") >= 0) url = "esf.rz.sdfdc";
	else if(area_code.indexOf("016011") >= 0) url = "esf.ly.sdfdc";
	else if(area_code.indexOf("016012") >= 0) url = "esf.zz.sdfdc";
	else if(area_code.indexOf("016013") >= 0) url = "esf.jin.sdfdc";
	else if(area_code.indexOf("016014") >= 0) url = "esf.ta.sdfdc";
	else if(area_code.indexOf("016015") >= 0) url = "esf.lw.sdfdc";
	else if(area_code.indexOf("016016") >= 0) url = "esf.bz.sdfdc";
	else if(area_code.indexOf("016017") >= 0) url = "esf.hz.sdfdc";
	else url = "esf.sdfdc";
	var act = "http://"+url+".com/fanba.php?callback=?&area_code="+area_code+"&addr="+addr;
	for(var i=ErShouFangListTable.rows.length-1;i>0;i--){ 
		        ErShouFangListTable.deleteRow(i); 
	} 
	var area_code="016001";
	$.getJSON(act,{},function(json){
		$.each(json,function(i,item){
			var newTr = ErShouFangListTable.insertRow();
			var newTd0 = newTr.insertCell();
			
			newTd0.innerHTML ='出售';
			newTd0 = newTr.insertCell();
			newTd0.innerHTML= '<a target="_blank" href="http://'+url+'.com/house/'+item.linkman+'">'+item.addr+'</a>';
			newTd0 = newTr.insertCell();
			newTd0.innerHTML=item.room_type+"";
			newTd0 = newTr.insertCell();
			newTd0.innerHTML =item.area_size+'m<sup>2</sup>';
			newTd0 = newTr.insertCell();
			newTd0.innerHTML=item.price+'万';
			newTd0 = newTr.insertCell();
			newTd0.innerHTML=item.sort_time;
			newTd0 = newTr.insertCell();
			newTd0.innerHTML='<a target="_blank"  href="http://'+url+'.com/house/'+item.linkman+'" >详细</a>';
		});
	});
		$("#House_More_Link").html('<p  class="a_right"><a href="http://'+url+'.com" target="_blank">[更多..]</a></p>');
}
function getBBS(){
	var floor_name=document.getElementById("floor_name_url").value;
	var keyword=document.getElementById("keyword").value;
	if(keyword==""){
		keyword=floor_name;
	}
	var url="http://bbs.qdfdc.com/funba_search.php?callback=?&search="+keyword;
	$.getJSON(url,{},function(xml){
	var newsConntent="";	
		$.each(xml, function (i, item) {
			newsConntent+='<li><h5><a target="_blank" href="http://bbs.qdfdc.com/viewthread.php?tid='+item.tid+'" >'+item.subject+'</a></h5><p>'+item.content+'</p></li>';		
		});
		if(newsConntent.length>100){
			$("#Floor_BBS").html(newsConntent);
		}else{
			$("#Floor_BBS").html('<li><span>暂无网评</span></li>');
		}
	});
	$("#Floor_BBS_more").html('<a href="http://bbs.qdfdc.com/search.php?searchid=$searchid&orderby=$orderby&ascdesc=$ascdesc&searchsubmit=yes&srchtxt='+keyword+'">更多</a>');
}
function addCookie(floors_id,floor_name,price){
	 var lps = get_cookie('lps');
//	 $.cookie('lps', null);return;	
	 if(lps==null || lps=='' || lps==undefined|| lps=="null"|| lps=='undefined'){
	 	 set_cookie('lps', floors_id+"#"+floor_name,24*360);
	 }else{
	  	var c= lps.split("#$");
	 	for (var i = 0; i < c.length; i++) {
			var floor=c[i].split("#");
			if(floors_id==floor[0])
			return;
			if(i>=10){
				var s=lps.indexOf('#$');				
				lps=lps.substring(s+2,lps.length);
			}
		}
	 	lps=lps+"#$"+floors_id+"#"+floor_name+"#"+price;
	 	set_cookie('lps',lps,24*360);
	 }
	 
}
function addCookieUch(){
	
	var str = $("#floor_name").val();
	str +="&nbsp;"+ $("#city_name_county_name").val();
	var avg_price = $("#avg_price").val();
	if(avg_price == null || avg_price == "" || avg_price == 0){
	avg_price = "暂时不详";}
	str += "&nbsp;"+avg_price+"&nbsp;";
	str += $("#floorsTuanGouCount").html();
	str += "&nbsp;"+$("#phone").val();
	url = window.location.href;
	
	 var lps = get_cookie('uch_lps');
//	 $.cookie('uch_lps', null);return;	
	 if(lps==null || lps=='' || lps==undefined|| lps=="null"|| lps=='undefined'){
	 	 set_cookie('uch_lps', url+"#"+str,24*360);
	 }else{
	  	var c= lps.split("#$");
	 	for (var i = 0; i < c.length; i++) {
			var floor=c[i].split("#");
			if(url==floor[0])
			return;
			if(i>=30){
				var s=lps.indexOf('#$');				
				lps=lps.substring(s+2,lps.length);
			}
		}
	 	lps=lps+"#$"+url+"#"+str;
	 	set_cookie('uch_lps',lps,24*360);
	 }
	 
}
////////////////////////////////////////////
function addCookie22(floors_id,floor_name){
	 var pls = get_cookie('pls');
	 if(pls==null || pls=='null'|| pls=='' || pls=='undefined'|| pls==undefined){
	 	 set_cookie('pls', floors_id+"#"+floor_name,24*360);
	 }else{
	  	var c= pls.split("#$");
	 	for (var i = 0; i < c.length; i++) {
			var floor=c[i].split("#");
			if(floors_id==floor[0])
			return;
			if(i>=7){
				var s=pls.indexOf('#$');				
				pls=pls.substring(s+2,pls.length);
			}
		}
	 	pls=pls+"#$"+floors_id+"#"+floor_name;
	 	set_cookie('pls',pls,24*360);
	 }
	 
}
function set_cookie(name,value,expireHours){
	var cookieString=name+"="+encodeURIComponent(value);
	//判断是否设置过期时间
	if(expireHours>0){
		var date=new Date();
		date.setTime(date.getTime() + expireHours*3600*1000);
		cookieString=cookieString+"; expire="+date.toUTCString();
	}
	cookieString=cookieString+"; path=/; domain=qdfdc.com";
//	alert(cookieString);
	document.cookie=cookieString;
} 
function get_cookie(name){
//alert(document.cookie);
	var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split('; ');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = cookies[i];
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
           }
        }
   }
   return unescape(cookieValue);
}
function deleteCookie(name){
	var date=new Date();
	date.setTime(date.getTime()-10000);
	document.cookie=name+"=v; expire="+date.toUTCString()+"; domain=qdfdc.com";
}
function uchGuanzhu(){
	window.open('http://home.sdfdc.com/space.php?do=buy&act=guanzhu_f&type=funba&url='+window.location.href);
}

