/*******************************************************************************
 * 异步登录处理
 */
function _ajaxLogin(_url) {
	$("#_login_message").html("请稍候，登录中...");
	$.ajax({
		type : "POST",
		url : _url,
		data : {
			account : $("#_account").val(),
			password : $("#_password").val()
		},
		async : true,
		success : function(msg) {
			tb_remove();
			window.location.replace(window.location.href);
		},
		error : function() {
			$("#_login_message").html("登录出现错误，请重试。");
		}
	});
}

/*******************************************************************************
 * 
 * 异步装载页面
 */
function _ajaxLoadPage(_url, _container, _callback) {
	if (_container) {
		$("#" + _container)
				.html("<div class=\"loadNoteDiv\">\u9875\u9762\u88c5\u8f7d\u4e2d\uff0c\u8bf7\u7a0d\u5019...</div>");
	}
	jQuery.ajax({
		type : "POST",
		url : _url,
		async : true,
		timeout:30000,
		success : function(msg) {
			if (_container) {
				jQuery("#" + _container).html(msg);
			}
			if (_callback != null && typeof _callback == "function") {
				_callback(msg);
			}
		},
		error : function() {
			if (_container) {
				jQuery("#" + _container + "_msg").html("页面装载异常。");
			}
		}
	});
}

/*******************************************************************************
 * 刷新验证码
 * update 2010-7-6 zhangys
 * update 2010-10-8 ouyj
 * type 验证码类型（A:文章 C:评论 M:留言 L:登录）
 * pojo_id 验证的对象ID,比如发表文章的用户ID
 */
function refreshVerifyCode(objA,objB,type,pojo_id) {
	var _context = "";
	if (window.APPLICATION_CONTEXT) {
		_context = APPLICATION_CONTEXT;
	} else if (parent.APPLICATION_CONTEXT) {
		_context = parent.APPLICATION_CONTEXT;
	}
	
	$.ajax({
		type : "POST",
		url : _context + "/verifycode2/refresh.jspx?type=" + type+pojo_id,
		async : true,
		success : function(msg) {
			if (objA!=null&&objB!=null) {
				var msgs = msg.split(",");
				var msgA = msgs[0];
				var msgB = msgs[1];
				$("#" + objA).html(msgA);
				$("#" + objB).attr("value",msgB);
			}
		}
	});
}

/*******************************************************************************
 * 发送短消息
 * option:{id:"消息接收者",communicateMessage:"消息类型[student-teacher|teacher-student]"}
 * student-teacher:学生向老师发送的申请消息 teacher-student:老师向学生发送的邀请信息
 */

function sendMessage(option) {
	var _context = "";
	if (window.APPLICATION_CONTEXT) {
		_context = APPLICATION_CONTEXT;
	} else if (parent.APPLICATION_CONTEXT) {
		_context = parent.APPLICATION_CONTEXT;
	}
	$.ajax({
		type : "POST",
		url : _context + "/message/communicate.jspx",
		data : option,
		async : true,
		success : function(msg) {
			alert(msg);
		},
		error : function() {

		}
	});
}

function communicate(incepter, messagetype) {
	var option = {};

	if (incepter == null || incepter == "") {
		alert("请指定消息接收者。");
		return;
	}

	if (messagetype == null || messagetype == "") {
		alert("请指定消息类型[student-teacher | teacher-student | friends]。");
		return;
	}

	option["id"] = incepter;
	option["communicateMessage"] = messagetype;

	sendMessage(option);
}

/*******************************************************************************
 * 发件箱
 */
function outbox(incepter, _b_link) {
	if (incepter == null || incepter == "") {
		alert("请指定消息接收者。");
		return;
	}

}

/*******************************************************************************
 * 将传过来的messagetype由整数类型，转换成对应的字符串
 */
function transfer(incepter, messagetype, usrId) {
	if (incepter == usrId) {
		alert("对不起，您不能添加自己为朋友！");
		return;
	}
	communicate(incepter, messagetype);
}

/*******************************************************************************
 * 初始化 thickbox
 */
function _init_thickbox(container) {
	if (container) {
		$(container).find(".thickbox").unbind("click").bind("click",
				function() {
					var t = this.title || $(this).html() || this.name || null;
					var a = this.href || this.alt;
					var g = this.rel || false;
					var ac = $(this).attr("afterclose") || null;
					tb_show(t, a, g, ac);
					this.blur();
					return false;
				});
	} else {
		$(".thickbox").unbind("click").bind("click", function() {
			var t = this.title || $(this).html() || this.name || null;
			var a = this.href || this.alt;
			var g = this.rel || false;
			var ac = $(this).attr("afterclose") || null;
			tb_show(t, a, g, ac);
			this.blur();
			return false;
		});
	}
}

/**
* 存档的全显示和部分显示。
* tangchen.
* 2010-4-30 
*/
$("#archive_button").toggle(function(){
var _context = "";
	if (window.APPLICATION_CONTEXT) {
		_context = APPLICATION_CONTEXT;
	} else if (parent.APPLICATION_CONTEXT) {
		_context = parent.APPLICATION_CONTEXT;
	}
		$("#archive_button").text("-");
		var id = $("span[@id=userId]").text();
		if ($("#showAllArchive").html() == "") {
			_ajaxLoadPage(_context + "/index/article/getArchives.jspx?blogUserId=" + id, "showAllArchive");
		}
		$("#showAllArchive").show();
		$("#archivesList").hide();
	},
	function(){
		$("#archive_button").text("+");
		$("#archivesList").show();
		$("#showAllArchive").hide();
});

