// JavaScript Document
jQuery(document).ready(function(){
	var ajaxurl="";
	
	/*绑定用户登录通知按钮*/
	if (document.getElementById("login_notice") != null) {
		/*我知道了*/
		jQuery("#colse_notice").one("click",function(){
			jQuery("#login_notice").slideUp();
		});
		
		
		var notice_arr = jQuery("#login_notice dd")
		if (notice_arr.size() > 3){
			notice_arr = notice_arr.slice(3, notice_arr.size())
			notice_arr.hide();
			
			jQuery("#switch_more_notice").toggle(function(){
				jQuery(this).html("收起-");
				notice_arr.slideDown(200);
			},function(){
				jQuery(this).html("展开+");
				notice_arr.slideUp(200);
			});
		}
		else jQuery("#switch_more_notice").hide();
	}

	//初始化问题关注按钮提示语、绑定单击事件
	jQuery("a[rel=focusTopic]").each(function(){
		var topicId = jQuery(this).attr("topicId");
		try{
			if(favourTopicIds){
				for(var index in favourTopicIds){
					if(favourTopicIds[index]==topicId) {
						jQuery(this).addClass("p-focused");	
						break;
					}
				}
			}
		}
		catch(e){
		
		}
	});
	
	
	jQuery("a.p-focus").attr("title","收藏该问题（再次点击取消）");
	jQuery("a.p-focused").attr("title","取消收藏");
	
	jQuery("a[rel=focusTopic]").bind("click",function(){
		var _this = jQuery(this)
		var topicId = _this.attr("topicId");
		var focused;
		if(_this.hasClass("p-focused")) focused = true;
		else focused =false;
		
		jQuery.ajax({
			url:"http://wenda.tianya.cn/wenda/topic",
			data:{
				'action':'focus',
				'topicId':topicId,
				'focus':focused?0:1, //已关注表示点击需要取消关注,否则反之
				'_':new Date().getTime()
			},
			dataType:'json',
			success:function(json){
				if(json.result == "success") {
					if(focused){
						_this.removeClass("p-focused");	
						focused = false;
					}
					else{
						_this.addClass("p-focused");
						focused = true;
					}
					if (!focused) _this.attr("title","收藏该问题（再次点击取消）")
					else _this.attr("title","取消收藏")
				}
			},
			error:function(){
				//alert("设置关注失败!");
			}
		});
		
		//_this.toggleClass("p-focused")

	});
	
	
	
	//初始化关注标签按钮提示语、绑定单击事件
	jQuery("a[rel=focusTag]").each(function(){
		var labelId = jQuery(this).attr("labelId");
		try{
			if(focusedTags){
				for(var index in focusedTags){
					if(focusedTags[index]==labelId) {
						jQuery(this).addClass("t-focused");	
						jQuery(this).show();
						break;
					}
				}
			}
		}
		catch(e){
		
		}
	});
	
	//初始化标签关注按钮提示语、绑定单击事
	jQuery("a.t-focus").attr("title","关注该标签（再次点击取消）");
	jQuery("a.t-focused").attr("title","取消关注");
	
	jQuery("a[rel=focusTag]").bind("click",function(){
		var _this = jQuery(this);
		var labelId = _this.attr("labelId");
		var focused;
		if(_this.hasClass("t-focused")) focused = true;
		else focused =false;
		
		jQuery.ajax({
			url:"http://wenda.tianya.cn/wenda/tag",
			data:{
				'action':'focus',
				'labelId':labelId,
				'focus':focused?0:1, //已关注表示点击需要取消关注,否则反之
				'_':new Date().getTime()
			},
			dataType:'json',
			success:function(json){
				if(json.result == "success") {
					if(focused){
						_this.removeClass("t-focused");	
						focused = false;
					}
					else{
						_this.addClass("t-focused");
						focused = true;
					}
					if (!focused) {
						_this.attr("title","关注该标签（再次点击取消）");
															
						for(index in focusedTags){
							if(focusedTags[index]==labelId){
								focusedTags[index]='';
							}
						}
					}
					else {
						focusedTags.push(''+labelId);
						_this.attr("title","取消关注");

					
					}
				}
			},
			error:function(){
				//alert("设置关注失败!");
			}
		});
	});
	
	//初始化标签关注按钮提示语、绑定单击事
	jQuery("a.r-focus").attr("title","关注该用户（再次点击取消）");
	jQuery("a.r-focused").attr("title","取消关注");
	
	jQuery("a.r-focus").bind("click",function(){
		var _this = jQuery(this);
		var userId = _this.attr("userId");
		var focused;
		if(_this.hasClass("r-focused")) focused = true;
		else focused = false;
		
		jQuery.ajax({
			url:"http://wenda.tianya.cn/wenda/userinfo",
			data:{
				'action':'focus',
				'userId':userId,
				'focus':focused?0:1, //已关注表示点击需要取消关注,否则反之
				'_':new Date().getTime()
			},
			dataType:'json',
			success:function(json){
				if(json.result == "success") {
					if(focused){
						_this.removeClass("r-focused");	
						focused = false;
					}
					else{
						_this.addClass("r-focused");
						focused = true;
					}
					if (!focused) _this.attr("title","关注该用户（再次点击取消）")
					else _this.attr("title","取消关注")
				}
			},
			error:function(){
				//alert("设置关注失败!");
			}
		});
	});	
	
	//标签页、找人页FOCUS反色,#user_list .user-list li
	jQuery("#tag_list .tag-list li").hover(
		function(){
			jQuery(this).addClass("bg");
			jQuery("a.t-focus,a.r-focus",this).show();
		},function(){
			jQuery(this).removeClass("bg");
			jQuery("a.t-focus,a.r-focus",this).not(".t-focused").hide();
		}
	)
	
	
	//绑定“回到顶部”事件
	jQuery(window).bind("resize scroll",setscroll_top);
	jQuery("#scroll_top").bind("click",function(){
		scrolltotop(jQuery(document).scrollTop());
		jQuery(this).fadeOut()
	});
	
	jQuery("#add_problem_txt").each(function(index){
	
		var len = getStrLen(jQuery(this).val());
		var remaining = 100 - len;

		remaining = (remaining % 2 ? remaining - 1 : remaining)/2
		
		if (remaining < 0) jQuery("#add_problem_leng").html("<b style=color:#f00>" + remaining + "</b>");
		else if (remaining <= 10) jQuery("#add_problem_leng").html("<b style=color:#f00>" + remaining + "</b>");
		else if (remaining > 10 && remaining <= 20) jQuery("#add_problem_leng").html("<b style=color:#B43C3C>" + remaining + "</b>");
		else jQuery("#add_problem_leng").html(remaining);
	});
		
	/* 计算输入字数 */
	if (document.getElementById("add_problem_txt") != null) {
		//让用户在复制文本时,把文本中的换行符替换成空格字符
		jQuery("#add_problem_txt").bind("paste",function(e){
					var el = jQuery(this);
					setTimeout(function(){
						var str = jQuery(el).val();
						str = str.replace(/\n/g," ");
						jQuery(el).val(str);
					},100);

		});

		
		jQuery("#add_problem_txt").bind("keyup click blur",function(eventObj){
		
			var len = getStrLen(jQuery(this).val());
			var remaining = 100 - len;

			remaining = (remaining % 2 ? remaining - 1 : remaining)/2
			
			if (remaining < 0) jQuery("#add_problem_leng").html("<b style=color:#f00>" + remaining + "</b>");
			else if (remaining <= 10) jQuery("#add_problem_leng").html("<b style=color:#f00>" + remaining + "</b>");
			else if (remaining > 10 && remaining <= 20) jQuery("#add_problem_leng").html("<b style=color:#B43C3C>" + remaining + "</b>");
			else jQuery("#add_problem_leng").html(remaining);
		}).bind("focus",function(){
			jQuery("#err_hint").html("")
		});
	}
	
	/*补充问题*/
	jQuery("#problem_ot_but").bind("click",function(){
		jQuery("#problem-ot").toggle();
		jQuery(this).toggleClass("seled");
	})
	
	jQuery("#but_content_edit").bind("click",function(){
		if (document.getElementById("content_edit") == null) {
			jQuery("#content_show").after(
				'<div id="content_edit" class="content_edit">' +
				'	<div><textarea name="add_problem_txt" cols="" rows=""></textarea></div>' +
				'	<div class="ot">' +
				'		<input id="but_content_show" name="" type="button" class="submit" value="确 定" />' +
				'	</div>' +
				'</div>'
			);
			jQuery("#but_content_show").bind("click",function(){
				jQuery("#content_edit").toggle();
				jQuery("#content_show").toggle();
			})
		}

		jQuery("#content_edit").toggle();
		jQuery("#content_show").toggle();
	})
	

	/*修改标签*/
	jQuery("#but_tags_edit").bind("click",function(){
		if (document.getElementById("tags_edit") == null) {
			jQuery("#tags_show").after(
				'<div id="tags_edit" class="tags_edit">' +
				'	<select id="type1" name="" onChange="redirect(this.options.selectedIndex)">' +
				'		<option value="1">考试</option>' +
				'		<option value="2">其它</option>' +
				'		<option value="3">其它2</option>' +
				'	</select>' +
				'	->' +
				'	<select id="type2" name="">' +
				'		<option></option>' +
				'	</select>' +
				'	<input id="but_tags_show" name="" type="button" class="submit2" value="确 定" />' +
				'</div>'
			);
			
			if(typeof(redirect_init) == "function") redirect_init("type1","type2");
			
			jQuery("#but_tags_show").bind("click",function(){
				jQuery("#tags_edit").toggle();
				jQuery("#tags_show").toggle();
			})
		}
		

		jQuery("#tags_edit").toggle();
		jQuery("#tags_show").toggle();
	})
	
	/*提交问题*/
	jQuery("#add_problem_sumit").bind("click",function(){
		var len = getStrLen(jQuery("#add_problem_txt").val());
		if (len == 0) {
			jQuery("#err_hint").html('请先输入你的问题再点击"提问"')
			return false;
		}
		else if (len < 10){
			jQuery("#err_hint").html("请输入至少5个字");
			return false;
		}
		else if(len >  100){
			jQuery("#err_hint").html('问题长度限于50个字以内，您可以在问题补充中补充问题。')
			return false;
		}
	})
	
	/*显示完整回答*/
	jQuery("a.showCompleteAnswer").bind("click",function(){
		jQuery(this).unbind().hide()
		jQuery(this).siblings(".small-answer").toggle();
		jQuery(this).siblings(".complete-answer").toggle();
	})
	
	/*显示所有赞同回答名单按钮*/
	jQuery(".answer-item .answer-content a.per").bind("click",function(){						   
		var p = jQuery(this).parent();
		var c = parseInt(jQuery(this).attr('count'));
		var followupId = jQuery(this).attr("followupId");
		if(c>0){
			jQuery.ajax({
				url:"http://wenda.tianya.cn/wenda/followup",
				data:{
					'action':'findVoteHistory',
					'followupId':followupId,
					'rate':'1',
					'_':new Date().getTime()
				},
				dataType:'json',
				success:function(json){
					if(json.result == "success") {
						jQuery(p).empty();
						var index;
						
						for(index in json.data){
							var link = '';
							if(index!=0) link=',';
							link = link+ '<a href="user?userid='+json.data[index].userId+'">'+json.data[index].userName+'</a>';
							jQuery(p).append(link);
						}
					}
					else{
						
					}
				},
				error:function(){
					
				}
			});
		}
	})
	
	/*投票按钮事件绑定*/
	jQuery(".answer-item .answer-content .menu a[rel='vote_up']").bind("click",function(){
		var th = jQuery(this);
		var topicId = jQuery(this).attr("topicId");
		var followupId = jQuery(this).attr("followupId");
		var uped = th.hasClass("uped");
		if(uped) return;
		var downed = jQuery(this).siblings("a[rel='vote_down']").hasClass("downed");
		
		jQuery.ajax({
			url:"http://wenda.tianya.cn/wenda/followup",
			data:{
				'action':'vote',
				'rate':'1',
				'topicId':topicId,
				'followupId':followupId,
				'ttt':new Date().getTime()
			},
			dataType:'json',
			success:function(json){
				if(json.result != "success") {
					alert("投票失败:"+json.reason);
				}
				else{
					if(downed){
						jQuery(th).siblings("a[rel='vote_down']").removeClass("downed");
						//反对人数-1
						var c = jQuery('span.downcount[followupId="'+followupId+'"]');
						var c2 = parseInt(jQuery(c).text())-1;
						jQuery(c).text(c2);
					}
					//赞成人数+1
					var t = jQuery('span.upcount[followupId="'+followupId+'"]');
					var t2 = parseInt(jQuery(t).text())+1;
					jQuery(t).text(t2);
					jQuery(th).addClass("uped");
				}
			},
			error:function(){
				alert("投票失败!");
			}
		});
		
	}).hover(function(){
		poptitle(jQuery(this),"赞成");
	},function(){
		jQuery("#poptitle").hide();
	})
	
	jQuery(".answer-item .answer-content .menu a[rel='vote_down']").bind("click",function(){		
		var th = jQuery(this);
		var topicId = jQuery(this).attr("topicId");
		var followupId = jQuery(this).attr("followupId");
		
		var downed = th.hasClass("downed");
		if(downed) return;
		var uped = jQuery(this).siblings("a[rel='vote_up']").hasClass("uped");
		
		jQuery.ajax({
			url:"http://wenda.tianya.cn/wenda/followup",
			data:{
				'action':'vote',
				'rate':'-1',
				'topicId':topicId,
				'followupId':followupId,
				'ttt':new Date().getTime()
			},
			dataType:'json',
			success:function(json){
				if(json.result != "success") {
					alert("投票失败:"+json.reason);
				}
				else{
					if(uped){
						jQuery(th).siblings("a[rel='vote_up']").removeClass("uped");
						//赞成人数-1
						var c = jQuery('span.upcount[followupId="'+followupId+'"]');
						var c2 = parseInt(jQuery(c).text())-1;
						jQuery(c).text(c2);
					}
					//反对人数+1
					var t = jQuery('span.downcount[followupId="'+followupId+'"]');
					var t2 = parseInt(jQuery(t).text())+1;
					jQuery(t).text(t2);
					jQuery(th).addClass("downed");
				}
			},
			error:function(){
				alert("投票失败!");
			}
		});
	}).hover(function(){
		poptitle(jQuery(this),"没有帮助(不会记录你的名字)");
	},function(){
		jQuery("#poptitle").hide();
	})

	/*回显当前用户投票记录*/
	jQuery(".answer-item .answer-content .menu a[rel='vote_up']").each(function(){
		var followupId = jQuery(this).attr("followupId");
		var index;
		for(index in voteupFollowups){
			if(voteupFollowups[index]==followupId) jQuery(this).addClass("uped");	
		}
	});

	jQuery(".answer-item .answer-content .menu a[rel='vote_down']").each(function(){
		var followupId = jQuery(this).attr("followupId");
		var index;
		for(index in votedownFollowups){
			if(votedownFollowups[index]==followupId) jQuery(this).addClass("downed");	
		}
	});
		
	/*设为最佳答案*/
	jQuery("a[rel='setoptimal']").bind("click",function(){							
		showpopoptimal(jQuery(this));
	})
	
	/*投诉*/
	jQuery("a[rel='complaint']").bind("click",function(){
		showpopcomplaint(jQuery(this));
	})
	
	/*隐藏自己的提问*/
	jQuery('a[rel="hideOwnerTopic"]').bind("click",function(){
		
		var topicId = jQuery(this).attr("topicId");
		if(!confirm("你确定要删除自己的问题吗?")) return false;
		
		jQuery.ajax({
			url:'http://wenda.tianya.cn/wenda/topic',
			data:{
				'action':'hideOwnerTopic',
				'topicId':topicId,
				'_':new Date().getTime()
			},
			dataType:'json',
			success:function(json){
				if(json.result == "success") {
					alert("删除问题成功");
					window.location = "http://wenda.tianya.cn/wenda";
				}
				else alert("删除问题失败:"+json.reason);
			},
			error:function(){
				alert("删除问题失败");
			}
		});
	});
	
	/*隐藏回复*/
	jQuery('a[rel="hideFollowup"]').bind("click",function(){
		if(!confirm("你确定要删除此条回答吗?")) return;
		
		var followupId = jQuery(this).attr("followupId");
		var topicId = jQuery(this).attr("topicId");
		
		jQuery.ajax({
			url:'http://wenda.tianya.cn/wenda/followup',
			data:{
				'action':'hideFollowup',
				'followupId':followupId,
				'topicId':topicId,
				'ttt':new Date().getTime()
			},
			dataType:'json',
			success:function(json){
				if(json.result == "success") {
					//alert("删除回答成功，你可以点击撤销删除进行恢复");
					var theDiv = jQuery("#div_"+followupId);
					jQuery(theDiv).removeClass("answer-item cf").addClass("hint-v");
					jQuery(theDiv).html('<strong>该回答已被删除</strong>,其它用户不能看到该回答,<a href="javascript:retrieveFollowup(\''+topicId+'\',\''+followupId+'\');" rel="retrieveFollowup" topicId="'+topicId+'" followupId="'+followupId+'">撤销删除</a>	');
				}
				else alert("删除回复失败:"+json.reason);
			},
			error:function(){
				alert("删除回复失败");
			}
		});
	});

	/*评论相关*/
	jQuery("a[rel='addcomment']").bind("click",function(){
		//通过ajax读取相应回复内容
		var commentDiv = jQuery(this).closest(".answer-item").find(".comment-content");
		var topicOwnerId = jQuery(this).attr("topicOwnerId");
		commentDiv.toggle();
		var isHidden = commentDiv.is(":hidden");
		var followupId = jQuery(this).attr("followupId");
		
		//评论框出现时,读取评论
		if(isHidden == false){
			jQuery.ajax(
				{
					url:'http://wenda.tianya.cn/wenda/comment',
					data:{
						'action':'getComments',
						'followupId':followupId,
						'ttt':new Date().getTime()
					},
					dataType:'json',
					success:function(json){
						commentDiv.find(".loading").hide();
						if(json ==null) return;
						if(json.result=="success"){
							var theUL = jQuery(commentDiv).find("ul");
							theUL.empty();
							var items = [];
							jQuery.each(json.data,function(index,comment){
								try{
									var myClass = "";
									if(comment.userId == topicOwnerId){
										myClass = 'class="me"';
									}
									var cc = '<li><p>'+comment.detail+'</p><a href="http://wenda.tianya.cn/wenda/user?userid='+comment.userId+'" '+myClass+'  _data="'+comment.userId+'"  _position="right" target="blank">'+comment.userName+'</a> | '+comment.pastCreateTime;
									try{
										if(showHideCommentButton==true){
											cc = cc+' | <a href="javascript:void(0);" rel="hideComment" commentId="'+comment.commentId+'" topicId="'+comment.topicId+'" followupId="'+comment.followupId+'">删除评论</a>';	
										}
									}
									catch(f){
									}
									cc = cc+'</li>';
									theUL.append(cc);
								}
								catch(e){
						
								}
							});
							
							
							/*隐藏评论*/
							jQuery("a[rel='hidecomment']").bind("click",function(){
								var topicId = jQuery(this).attr("topicId");
								var followupId = jQuery(this).attr("followupId");
								var commentId = jQuery(this).attr("commentId");
								var parentLi = jQuery(this).parent();
								jQuery.ajax({
									url:'http://wenda.tianya.cn/wenda/comment',
									data:{
											'action':'hideComment',
											'topicId':topicId,
											'followupId':followupId,
											'commentId':commentId,
											'ttt':new Date().getTime()
									},
									dataType:'json',
									success:function(json){
										parentLi.fadeOut(300);
										var commentCount = jQuery('a[rel="addcomment"][followupId="'+followupId+'"] span');
										var cc = parseInt(jQuery(commentCount).text())-1;
										jQuery(commentCount).text(cc);
									},
									error:function(){
										alert("删除评论失败");
									}
								});
							});
						}
						else{
							alert(json.reason);	
						}
						

						//for(var comment : json){
								//theUL.append('<li><p>'+comment.detail+'</p><a href="" class="me" _data="'+comment.userId+'" rel="user_pop" _position="right">'+comment.userName+'</a></li>');
						//}
					},
					error:function(){
						commentDiv.find(".loading").hide();
						alert("读取评论失败!");
					}
				}
				
			);
		}
	});

	
	/*发布评论*/
	jQuery('.comment-add input[name="submit"]').click(function(){
		var topicId = jQuery(this).attr("topicId");
		var followupId = jQuery(this).attr("followupId");
		var detail = jQuery('.comment-add textarea[name="commentDetail"][followupId="'+followupId+'"]').val();

		jQuery.ajax(
			{
				url:'http://wenda.tianya.cn/wenda/comment',
				data:{
					'action':'addComment',
					'topicId':topicId,
					'followupId':followupId,
					'detail':detail,
					'ttt':new Date().getTime()
				},
				dataType:'json',
				success:function(json){
					if(json==null) {
						alert("发布评论失败!");
						return;
					}
					
					if(json.result=="success"){
						
						var d = jQuery('<li><p>'+json.data.detail+'</p><a href="" _data="'+json.data.userId+'"  _position="right">'+json.data.userName+'</a> | 0分钟前</li>').hide().fadeIn(1000);
						//将内容增加到评论div下面
						jQuery('.comment-content[followupId="'+followupId+'"] ul').append(d);
						
						var commentCount = jQuery('a[rel="addcomment"][followupId="'+followupId+'"] span');
						var cc = parseInt(commentCount.text());
						if(isNaN(cc)){
							 jQuery('a[rel="addcomment"][followupId="'+followupId+'"]').append('(<span>1</span>)');
							 jQuery('.comment-add textarea[name="commentDetail"][followupId="'+followupId+'"]').val("");
							 return;
						}
						else{
							cc = cc +1;
							jQuery(commentCount).text(cc);
							jQuery('.comment-add textarea[name="commentDetail"][followupId="'+followupId+'"]').val("");
						}

					}
					else{
						alert("发布评论失败:"+json.reason);
					}
				},
				error:function(){
					alert("发布评论失败");
				}
			}
			
		);		
		
	});

	jQuery("a[rel='closecomment']").bind("click",function(){
		jQuery(this).closest(".comment-content").hide();
	})
	

	//绑定标签提示框
	if(jQuery("a[rel='tag_pop']").size() > 0){
		var pop_tag_id=0,pop_tag_timeout=null;
		jQuery("body").append(
			'<div id="tag_info_box" class="pop-box">'+
			'	<div id="tag_main" class="box-main">'+
			'		<a href="#" target="_blank" class="name"></a>'+
			'		<p class="tag-info"></p>'+
			'		<p class="p-count"></p>'+
			'	</div>'+
			'	<div class="d_focus">'+
			'		<a href="javascript:void(0);" _data="t_id" class="focus"><!--关注/取消关注--></a>'+
			'		<a href="#" class="fans">zxczxczc</a>'+
			'	</div>'+
			'	<div class="loading">正在加载中....</div>'+
			'</div>'
		)
		
		jQuery("#tag_info_box .d_focus a.focus").bind("click",function(){
			var _this = jQuery(this)

			//加入AJAX处理过程
			
			_this.toggleClass("focused")
			if (_this.attr("title") == "取消关注") _this.attr("title","关注该标签（再次点击取消）")
			else _this.attr("title","取消关注")
		});/*需增加AJAX处理*/
		
		jQuery("#tag_info_box").bind("mouseover",function(){ 
			clearTimeout(pop_tag_timeout);		  
			//alert("c2"+pop_tag_timeout)
		}).bind("mouseout",function(){
			pop_tag_timeout = setTimeout(function(){jQuery("#tag_info_box").hide();},200);
			//alert("a2"+pop_tag_timeout)
		})
		
		jQuery("a[rel='tag_pop']").bind("mouseover",function(){ 
			clearTimeout(pop_tag_timeout);
			//alert("c1"+pop_tag_timeout)
			var $tag_info_box = jQuery("#tag_info_box");
			popLoading($tag_info_box);
															
			var top = jQuery(this).offset().top + jQuery(this).outerHeight(true) - $tag_info_box.outerHeight(true);
			top = top > jQuery(document).scrollTop() ? top : jQuery(this).offset().top;
			
			var left = jQuery(this).attr("_position") == "left" ? jQuery(this).offset().left - $tag_info_box.outerWidth(true) -5: jQuery(this).offset().left + jQuery(this).outerWidth(true) + 5 ;
			$tag_info_box.css({"left":left,"top":top});
			
			$tag_info_box.show();
			
			/*以下为AJAX处理显示*/
			/*
			
			pop_tag_id = jQuery(this).attr("_data");
			
			jQuery.getJSON(
				ajaxurl + "",
				{"userId":__global.getUserId(),t_id:jQuery(this).attr("_data")"random":Math.random()},
				function(ReturnStr){
					if (ReturnStr!=null){
						if (ReturnStr.success){
							if (pop_tag_id == ReturnStr.t_id)
			*/
								$tag_info_box.find(".box-main a.name").html("消费1")
																		.attr("href","tag_problem_list.html?" + "sdfs");
								$tag_info_box.find(".box-main .tag-info").html("人们通过消费品，满足自身需求的一种经济行为")
								$tag_info_box.find(".box-main .p-count").html("今日新增1个问题，3个问答，<br/>共有87个问题。")
								$tag_info_box.find(".d_focus a.focus").attr("_data","5")
																		.removeClass("focused")
																		.attr("title","关注该标签（再次点击取消）");
								$tag_info_box.find(".d_focus a.fans").html("147人关注")
																		.attr("href","find.html?" + "sdfs")
																		
								
								popLoaded($tag_info_box);
			/*
							}
						}
						else return false;
					}
					else alert("程序发生错误，请联系管理员！\n错误提示：ReturnStr 为 Null");
				}
			);
			*/
		}).bind("mouseout",function(){
			//
			pop_tag_timeout = setTimeout(function(){jQuery("#tag_info_box").hide();},200);
			//alert("a1"+pop_tag_timeout)
		})
	}
	
	//绑定用户提示框
	if(jQuery("a[rel='user_pop']").size() > 999){
		var pop_user_id=0,pop_user_timeout=null;
		jQuery("body").append(
			'<div id="user_info_box" class="pop-box">'+
			'	<div id="user_main" class="box-main">'+
			'		<a href="#" target="_blank" class="user_url"><img class="hp" src="" /></a>'+
			'		<div id="user_main_txt"></div>'+
			'	</div>'+
			'	<div class="d_focus">'+
			'		<a href="javascript:void(0);" _data="user_id" class="focus"><!--关注/取消关注--></a>'+
			//'		<a href="find.html">147人关注</a>'+
			'	</div>'+
			'	<div class="loading">正在加载中....</div>'+
			'</div>'
		)

		jQuery("#user_info_box .d_focus a.focus").bind("click",function(){
			var _this = jQuery(this)

			//加入AJAX处理过程
			
			_this.toggleClass("focused")
			if (_this.attr("title") == "取消关注") _this.attr("title","关注该用户（再次点击取消）")
			else _this.attr("title","取消关注")
		});/*需增加AJAX处理*/
		
		jQuery("#user_info_box").bind("mouseover",function(){ 
			clearTimeout(pop_user_timeout) 	  
		}).bind("mouseout",function(){
			pop_user_timeout = setTimeout(function(){jQuery("#user_info_box").hide();},200)
		});
		
		
		jQuery("a[rel='user_pop']").bind("mouseover",function(){
			pop_user_id = jQuery(this).attr("_data");
			if (pop_user_id != __global.getUserId()){
				clearTimeout(pop_user_timeout) 
				var $user_info_box = jQuery("#user_info_box");
				popLoading($user_info_box);
																
				var top = jQuery(this).offset().top + jQuery(this).outerHeight(true) - $user_info_box.outerHeight(true);
				top = top > jQuery(document).scrollTop() ? top : jQuery(this).offset().top;
				
				var left = jQuery(this).attr("_position") == "right" ? jQuery(this).offset().left + jQuery(this).outerWidth(true) + 5 : jQuery(this).offset().left - $user_info_box.outerWidth(true) -5;
				$user_info_box.css({"left":left,"top":top});
				
				//$user_info_box.show();
				
				//以下为AJAX处理显示
				jQuery.getJSON(
					"http://wenda.tianya.cn/wenda/userinfo",
					{'userId':jQuery(this).attr("_data"),
					 'action':'show'	
					},
					function(ReturnStr){
						if (ReturnStr!=null){
							if (ReturnStr.result=="success"){
									$user_info_box.show();				
									$user_info_box.find(".box-main a.user_url").attr("href","http://wenda.tianya.cn/wenda/user?userid="+pop_user_id);
									$user_info_box.find(".box-main .hp").attr("src","http://tx.tianyaui.com/logo/"+pop_user_id);
									$user_info_box.find(".box-main #user_main_txt").html(
										'<a href="my_host.html target="_blank" class="name">'+ReturnStr.data.user.name+'</a>'+
										'<p>'+ReturnStr.data.user.topicCount+'个提问 | '+ReturnStr.data.user.followupCount+'个回答</p>'+
										'<p>'+ReturnStr.data.user.description+'</p>'
									)
									$user_info_box.find(".d_focus a.focus").attr("_data","5")
																			.removeClass("focused")
																			.attr("title","关注该用户（再次点击取消）");
									//$user_info_box.find(".d_focus a.fans").html("147人关注").attr("href","find.html?" + "sdfs");
									popLoaded($user_info_box);
			
							}
						}
						//else alert("程序发生错误，请联系管理员！\n错误提示：ReturnStr 为 Null");
						else return false;
					}
				);
			
			}
		}).bind("mouseout",function(){
			pop_user_timeout = setTimeout(function(){jQuery("#user_info_box").hide();},200);
		});
		
		
	
	}
})

/*恢复显示回复*/
function retrieveFollowup(tid,fid){
	
	jQuery.ajax({
		url:'http://wenda.tianya.cn/wenda/followup',
		data:{
			'action':'retrieveFollowup',
			'followupId':fid,
			'topicId':tid,
			'ttt':new Date().getTime()
		},
		dataType:'json',
		success:function(json){
			if(json.result == "success") {
				window.location.reload();
			}
			else alert("恢复失败");
		},
		error:function(){
			alert("恢复失败");
		}
	});
	
}

function JudgeIE6 (){
	var Sys = {};
	var ua = navigator.userAgent.toLowerCase();
	if (window.ActiveXObject)
		Sys.ie = ua.match(/msie ([\d.]+)/)[1]
	
	if (Sys.ie == "6.0") return true;
	else return false;
}

function scrolltotop(o_scrollTop){
	if (o_scrollTop > 1){
		o_scrollTop = o_scrollTop * 0.6;
		scroll(0,o_scrollTop);
		//scrolltotop(o_scrollTop)
		setTimeout(function(){scrolltotop(o_scrollTop);},10)
	}
	else{
		scroll(0,0)
		return false;
	}
};

//设置“回到顶部”位置
var st_scroll_top_show;
var setscroll_top = function(){
	if(jQuery(document).scrollTop() > 100){
		var _scroll_top = jQuery("#scroll_top");
		var _main_area = jQuery("#main_area");
		
		_scroll_top.hide();
		clearTimeout(st_scroll_top_show);
		
		var st_top = jQuery(window).height() + jQuery(document).scrollTop() -120;
		var st_left = _main_area.offset().left + _main_area.outerWidth();
		var max_top = _main_area.offset().top + _main_area.outerHeight() - _scroll_top.outerHeight()
		
		_scroll_top.css({ top: st_top > max_top ? max_top : st_top + "px", left:  +  st_left + "px" });
		st_scroll_top_show = setTimeout(function(){_scroll_top.show()},100);
		//_scroll_top.show()
	}
	else{
		clearTimeout(st_scroll_top_show);
		jQuery("#scroll_top").fadeOut()
	}
}

function popLoading(obj){
	obj.find(".box-main").hide();
	obj.find(".d_focus").hide();
	obj.find(".loading").show();
}

function popLoaded(obj){
	obj.find(".box-main").show();
	obj.find(".d_focus").show();
	obj.find(".loading").hide();
}

function getStrLen(s){
	var len=0;
	for(var i=0;i<s.length;i++){
		len += s.charCodeAt(i)>128?2:1
	}
	return len; 
}

/*投票提示语弹框创建、定位、显示*/
function poptitle(obj,title_str){
	if (document.getElementById("poptitle") == null) {
		jQuery("body").append('<div id="poptitle"><span><!--赞同--></span></div>')
	}
	
	var _self = jQuery("#poptitle")
	_self.css({ top: obj.offset().top + "px", left:  obj.offset().left + 25 + "px" })
	_self.find("span").html(title_str);
	_self.show();
}

/*设为最佳答案弹框创建、定位、数据处理、显示*/
function showpopoptimal(obj){
	if (document.getElementById("popoptimal") == null) {
		jQuery("body").append(
			'<div id="popoptimal"><!--设置最佳答案-->' +
			'	<div class="main">' +
			'		<p>确认将此答案设为最佳答案？此操作不可更改</p>' +
			'		<input rel="optimal_submit" name="" type="button" value="确认" class="submit2" />' +
			'		<input rel="optimal_cancel" name="" type="button" value="取消" class="but-2"  />' +
			'	</div>' +
			'	<div class="arrow"></div>' +
			'</div>'
		);
	}
	var followupId = obj.attr("followupId");
	var answer_item = obj.closest(".answer-item");
	var _self = jQuery("#popoptimal");
	
	_self.css({ top: -1000 + "px", left: -1000 + "px" });
	_self.show();
	_self.css({ top: obj.offset().top - _self.outerHeight() - 5 + "px", left:  obj.offset().left + 5 + "px" })
	
	_self.find("input[rel='optimal_submit']").bind("click",function(){
		jQuery("#bestFollowupId").attr("value",followupId);
		//answer_item.find(".answer-content .menu").append('<span class="optimaled" title="该回答被提问者选为最佳答案"><!--最佳答案--></span>');
		jQuery("#popoptimal").hide();
		jQuery("#chooseBestAnswer").submit();
		
		//_self.find("input[rel='optimal_submit']").unbind();
		//_self.find("input[rel='optimal_cancel']").unbind();
		//jQuery("a[rel='setoptimal']").closest("label").hide();
	});
	
	_self.find("input[rel='optimal_cancel']").bind("click",function(){
		jQuery("#popoptimal").hide();
		_self.find("input[rel='optimal_submit']").unbind();
		_self.find("input[rel='optimal_cancel']").unbind();
	})
}

/*投诉弹框创建、定位、数据处理、显示*/
function showpopcomplaint(obj){
	var main_html = '		<ul>' +
					'			<li>我认为“<strong id="complaint_title">...</strong>”涉及：</li>' +
					'			<li><input name="reason" type="radio" value="1" class="checkbox" checked onclick="if(this.checked) jQuery(\'#complaint\').hide()" />广告</li>' +
					'			<li><input name="reason" type="radio" value="2" class="checkbox" onclick="if(this.checked) jQuery(\'#complaint\').hide()" />敏感问题</li>' +
					'			<li><input name="reason" type="radio" value="3" class="checkbox" onclick="if(this.checked) jQuery(\'#complaint\').show()" />其它（需要输入投诉说明）</li>' +
					'			<li id="complaint"><input id="complaintDesc" name="complaintDesc" type="text" class="txt-1" /></li>' +
					'			<li class="buts">' +
					'				<input rel="complaint_submit" type="button" value="提交" class="submit3" />' +
					'				<input rel="complaint_cancel" type="button" value="放弃" class="but-3" />' +
					'			</li>' +
					'		</ul>' 
												   
	if (document.getElementById("popcomplaint") == null) {
		jQuery("body").append(
			'<div id="popcomplaint" class="cf">' +
			'	<div class="arrow"></div>' +
			'	<div class="main">' +
			main_html +
			'	</div>' +
			'</div>'
		);
	}
	else {
		jQuery("#popcomplaint .main").html(main_html);
		jQuery("#popcomplaint").removeClass("popcomplaint_o");
	}
	
	var _self = jQuery("#popcomplaint");
	var formtype = obj.attr("_type")
	//var item_id = obj.closest("_data");

	var _title = formtype == "topic" ? jQuery("#problem_area .problem-title h1").text() : obj.closest(".answer-item").find(".answer-content li.content").text()
	
	_self.find("#complaint_title").html(_title.length > 22 ? _title.substring(0,20) + "..." : _title)
	
	_self.css({ top: -1000 + "px", left: -1000 + "px" });
	_self.show();
	_self.css({ top: obj.offset().top - _self.outerHeight() + obj.outerHeight() + 7 + "px", left: obj.offset().left + obj.outerWidth() + 5 + "px" })
	

	_self.find("input[rel='complaint_submit']").bind("click",function(){	
		var complaintType = jQuery(obj).attr("_type");
		var targetId = jQuery(obj).attr("_data");
		var complaintReason = jQuery('[name="reason"]:checked').val();
		var complaintDesc = jQuery('#complaintDesc').val().trim();


		if(complaintReason=="3" && complaintDesc == ""){
			jQuery('#complaintDesc').focus();
			alert("请填写投诉原因!");
			return;	
		}
		if(complaintDesc.length > 200)complaintDesc = complaintDesc.substring(0,200);


		var userId = jQuery(obj).attr("userId");
		if(complaintType=="answer"){
			var tid = jQuery(obj).attr("topicId");
			jQuery.post(
			  'http://wenda.tianya.cn/wenda/complaint?action=add',
			  {'complaintType':complaintType,'userId':userId,'topicId':tid,'followupId':targetId,'reason':complaintReason,'complaintDesc':complaintDesc}
			);
		}
		else if(complaintType=="topic"){
			jQuery.post(
			  'http://wenda.tianya.cn/wenda/complaint?action=add',
			  {'complaintType':complaintType,'userId':userId,'topicId':targetId,'reason':complaintReason,'complaintDesc':complaintDesc}
			);
		}
		

					  
		_self.find(".main").html("投诉成功");			  
		_self.addClass("popcomplaint_o");
		_self.css({ top: obj.offset().top - _self.outerHeight() + obj.outerHeight() + 7 + "px", left: obj.offset().left + obj.outerWidth() + 5 + "px" })
		_self.find("input[rel='optimalcomplaint_submit']").unbind();
		_self.find("input[rel='complaint_cancel']").unbind();
		_self.fadeOut(1500);
	});
	
	_self.find("input[rel='complaint_cancel']").bind("click",function(){
		jQuery("#popcomplaint").hide();
		_self.find("input[rel='optimalcomplaint_submit']").unbind();
		_self.find("input[rel='complaint_cancel']").unbind();
	})
}
