function reply(comment_id, nickname){
	$('#content').html('[reply=#comment-' + comment_id + ']@' + nickname + '[/reply] ');
	$('#following_id').val(comment_id);
	//checkLength($('#content'));
}
function checkLength(which){ 
	var maxChars = 140;
	if(which.value.length > maxChars) 
		which.value = which.value.substring(0, maxChars); 
	var curr = maxChars - which.value.length; 
	document.getElementById("counter").innerHTML = curr.toString(); 
}
function share(sns){
	switch(sns){
		case "st":
			var f = 'http://v.t.sina.com.cn/share/share.php?', u = document.location.href, p = ['url=', encodeURIComponent(u), '&title=', encodeURIComponent(document.title), '&appkey=2924220432'].join('');
			if(/Firefox/.test(navigator.userAgent)){
				setTimeout(
					function(){
						if(!window.open([f, p].join(''), 'mb', ['toolbar=0,status=0,resizable=1,width=620,height=450,left=', (screen.width - 620) / 2, ',top=', (screen.height - 450) / 2].join(''))) u.href = [f, p].join('');
					}, 0
				);
			}else{
				if(!window.open([f, p].join(''), 'mb', ['toolbar=0,status=0,resizable=1,width=620,height=450,left=', (screen.width - 620) / 2, ',top=', (screen.height - 450) / 2].join(''))) u.href = [f, p].join('');
			}
			break;
		case "db":
			var d = document, e = encodeURIComponent, s1 = window.getSelection, s2 = d.getSelection, s3 = d.selection, s = s1 ? s1() : s2 ? s2() : s3 ? s3.createRange().text:'', r = 'http://www.douban.com/recommend/?url=' + e (d.location.href) + '&title=' + e(d.title) + '&sel=' + e(s) + '&v=1';
			if(/Firefox/.test(navigator.userAgent)){
				setTimeout(
					function(){
						if(!window.open(r, 'douban', 'toolbar=0,resizable=1,scrollbars=yes,status=1,width=450,height=330')) location.href = r + '&r=1'
					}, 0
				)
			}else{
				if(!window.open(r, 'douban', 'toolbar=0,resizable=1,scrollbars=yes,status=1,width=450,height=330')) location.href = r + '&r=1'
			}
			break;
		case "qz":
			window.open('http://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?url=' + encodeURIComponent(document.location.href));
			break;
		case "dg":
			window.open('http://www.diguff.com/diguShare/bookMark_FF.jsp?title=' + encodeURIComponent(document.title) + '&amp;url=' + encodeURIComponent(location.href), '_blank', 'width=580,height=310');
			break;
		case "kx":
			window.open('http://www.kaixin001.com/~repaste/repaste.php?rurl=' + encodeURIComponent(document.location.href.replace('#none', '')) + '&amp;rtitle=' + encodeURIComponent(document.title) + '&amp;rcontent=' + encodeURIComponent(document.title + ' ' + document.location.href.replace('#none', '')) + '');
			break;
		case "rr":
			var u = 'http://share.renren.com/share/buttonshare.do?link=' + encodeURIComponent(document.location.href.replace('#none','')) + '&amp;title=' + encodeURIComponent(document.title);
			window.open(u,'xiaonei','toolbar=0,resizable=1,scrollbars=yes,status=1,width=626,height=436');
			break;
		case "gb":
			window.open('http://www.google.com/buzz/post?url=' + encodeURIComponent(document.location.href));
			break;
		case "yb":
			window.open('http://myweb.cn.yahoo.com/popadd.html?url=' + encodeURIComponent(document.location.href) + '&title=' + encodeURIComponent(document.title), 'Yahoo', 'scrollbars=yes,width=500,height=470,left=80,top=80,status=yes,resizable=yes');
			break;
	}
}
function show_msg(msg, timeout){
	$("#result").html(msg).fadeIn();
	if(timeout != 0){
		setTimeout(function(){
			$("#result").fadeOut();
		}, (timeout ? timeout : 3000));
	}
}
function comment(){
	var content = $("#content").val();
	var verifycode = $("#verify_code").val();
	var parent_id = $("#parent_id").val();
	var following_id = $("#following_id").val();
	var nickname = $("#nickname").val();
	var email = $("#email").val();
	var url = $("#url").val();
	var form_action = $("#add_comment").attr("action");
	if(!nickname){
		show_msg("请输入您的昵称！");
		return false;
	}else if(!email){
		show_msg("请输入您的邮箱！");
		return false;
	}else if(verifycode.length < 4){
		show_msg("请输入验证码！");
		return false;
	}else if(!content){
		show_msg("请输入评论内容！");
		return false;
	}
	$("#cmnt_btn").attr("disabled", "disabled");
	show_msg("正在提交...", 0);
	$.post(form_action, {"content" : content, "verify" : verifycode, "parent_id" : parent_id, "following_id" : following_id, "nickname" : nickname, "email" : email, "url" : url}, function(data){
		var data = eval('(' + data + ')');
		show_msg(data.info);
		$("#cmnt_btn").removeAttr("disabled");
		$('#following_id').val('');
		if(data.status == 1){
			html = 
				'<dl id="comment-491" class="common-list cmnt-result">\
        			<dd class="avt"><img class="comment-people-pic f_l" src="' + data.data.pic + '" /></dd>\
					<dt><span class="cmnt-user">' + data.data.nickname + '</span> ' + data.data.postdate + '</dt>\
					<dd>' + data.data.content + '</dd>\
					<div class="clear"></div>\
				</dl>';
			$("#add_comment").after(html);
			flesh_verify();
			$("#content").val("");
			$("#verify_code").val("验证码");
		}
	});
}
function set_cookie(name, value){
    var Days = 30;
    var exp  = new Date();
    exp.setTime(exp.getTime() + Days * 24 * 60 * 60 * 1000);
    document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString();
}
function get_cookie(name){
    var arr = document.cookie.match(new RegExp("(^| )" + name + "=([^;]*)(;|$)"));
    if(arr != null) return unescape(arr[2]); return null;
}
function del_cookie(name){
    var exp = new Date();
    exp.setTime(exp.getTime() - 1);
    var cval = get_cookie(name);
    if(cval != null) document.cookie = name + "=" + cval + ";expires=" + exp.toGMTString();
}
jQuery(function($){
	$("#search_radio span").each(function(){
		$(this).click(function(){
			$("#search_radio span").each(function(){
				$(this).removeClass("cur");									  
			});
			$(this).addClass("cur");
			$("#search_type").val($(this).attr("name"));
		});								  
	});
	if(41 < $(".qtt-detail").height()){
		$(".qtt-detail").css("text-align", "left");
	}
	$(".share a").each(function(){
		$(this).click(function(){
			share($(this).attr("class").substr(2));
		});
	});
	$(".user-info-btn").click(function(){
		$(".user-input").slideToggle("slow");
	});
	$("dl[class=common-list]").each(function(){
		$(this).children("dd[class!=avt]").children("a").hover(
			function(){
				var href = $(this).attr("href");
				if(href.indexOf("comment-") > 0 && $("#comment-" + href.substr(9)).html()){
					var content = '<dl class="common-list" style="border-bottom:none;">' + $("#comment-" + href.substr(9)).html() + '</dl>';
					if(!$("#following_cont").html()){
						$("body").append('<div id="following_cont" style="display:none;">' + content + '</div>');
					}else{
						$("#following_cont").html(content);
					}
					$("#following_cont").fadeIn("slow");
					$("#following_cont").css({"top" : $(this).offset().top + 18, "left" : $(this).offset().left, "position" : "absolute", "background" : "#FFF", "width" : "570px", "border" : "1px solid #EC9436", "padding" : "0 10px"});
					$("#following_cont a").remove(".reply");
				}
			},
			function(){
				$("#following_cont").fadeOut("slow");
			}
		);
	});
	/*
	if(get_cookie("rifuyiri_switch_screen") == "widescreen"){
		$(".show").removeClass("show-narrow");
		$("#switch_screen").html("标准模式").addClass("narrowscreen-btn");
	}
	*/
	$(".cmnt .common-list").each(function(){
		$(this).hover(
			function(){
				$(this).children("dt").children(".reply").show();
			},
			function(){
				$(this).children("dt").children(".reply").hide();
			}
		);
	});
});







