﻿<!--

$(function(){
	$('#index_dialog_subscribe').dialog({
		autoOpen: false,
		width: 360,
		height: 240,
		buttons: {
			"Subscribe/订阅": function(){
				$(this).dialog('close');
			}
		}
	});
	
	$('#index_button_subscribe').click(function(){
		$('#index_dialog_subscribe').dialog('open');
	});
	
	$('#index_button_do_post').click(function(){
	
		//var data = {c:'content', t:'test'};
		//alert(data.c);
		
		//return;
		
		var topical = $('#index_text_topical').val();
		var comment = $('#index_text_comment').val();
		
		//输入有效性检测
		if(jQuery.trim(topical) == ''){
			$('#span_info').text('主题必填');
			$('#index_text_topical').focus();
			return;
		}
		if(jQuery.trim(comment) == ''){
			$('#span_info').text('内容必填');
			$('#index_text_comment').focus();
			return;
		}
		if(jQuery.trim(comment).length > 200){
			$('#span_info').text('内容不能超过200字');
			return;
		}
		
		topical = encodeURI(topical);
		comment = encodeURI(comment);
		var md5str = md5(topical + comment);
		
		$.post("php.user/comment.post.php", { topical: topical, comment: comment, md5str: md5str }, 
			function(data){
				//var obj = eval('(' + String(data) + ')');
				//TODO:show the new comment
				//TODO:处理错误
				//$('#div_list_comment ul').prepend('<p>' + String(obj.comment) + '</p>');
								
				//success
				//$('#span_info').text('');
				get_latest_root_comment();
			});
	});
	
	$('#index_text_comment').keypress(function(event){
		if($(this).val().length > 200){
			$('#span_info').text('内容不能超过200字');
			$(this).val($(this).val().substring(0, 200));
			return;
		}
	});
	
	get_latest_root_comment();
});

var get_latest_root_comment = function(){
	//show latest topical and it's comments
	$.get("php.user/comment.get.php", function(data){
		var obj = eval('(' + String(data) + ')');
		var t = $('#div_latest_topical a:last');
		t.html(obj.CMT_ON);
		t.attr('href', obj.CMT_ON);
		
		var c = $('#div_latest_content');
		c.html(obj.CMT_CONTENT);
	});
}

-->