var _is_error;
var _m_result;
var _l_url = "http://bbs.sina.com.cn/iframe/loading.html";
dw('<style type="text/css">\
#card_zone{width:100%;height:100%;position:relative;border:1px solid #CCC;top:-7px !important;left:-7px !important;top:-5px;left:-5px; background:#FFF;}\
</style>');
dw('<div id="user_card" style="background:#DFDFDF;width:0px; height:0px;top:0px;left:0px;position:absolute;display:none;z-index:100;">\
	<div id="card_zone"><iframe frameborder="0" width="100%" height="100%" src="' + _l_url + '" scrolling="no" id="iframe_user_card"></iframe></div>\
</div>');
function message(){
	this.act	= "";
	this.val	= Array();
	this.URI	= "http://bbs.service.sina.com.cn/forum/message.php";
	var _AJAX = new _ajax();
	_AJAX.init();
	_AJAX.setPost();
	this.set_act = function(act){
		this.act = act;
	}
	this.set_val = function(v){
		this.val.push(encodeURIComponent(v));
	}
	this.execute = function(callback){
		if (typeof(callback) != "function"){
			return false;
		}
		if (this.act == ""){
			return false;
		}
		_AJAX.open(this.URI + "?act=" + this.act + "&val=" + this.val.join("|"), function(){
			_is_error = $t("info",this.responseXML)[0].firstChild.nodeValue;
			var rt = $t("result",this.responseXML)[0].firstChild.nodeValue;
			if (_is_error == "1" && !isNull(rt)){
				eval("_m_result = " + rt);
			}
			callback.apply();
		});
		_AJAX.send();
		this.clear();
	}
	this.clear = function(){
		this.val = Array();
	}
}
{
	var user_card = new Object();
	user_card.w1 = "310px";		//名片
	user_card.h1 = "160px";
	user_card.w2 = "270px";		//发送邀请
	user_card.h2 = "204px";
	user_card.w3 = "197px";		//新消息
	user_card.h3 = "112px";
	user_card.obj = $("user_card");
	user_card.ifm = $("iframe_user_card");
	user_card.dcmt = (document.documentElement) ? document.documentElement : document.body;
	user_card.reset = function(){
		$("iframe_user_card").src = _l_url;
		user_card.obj.style.display = 'none';
		document.body.onclick = null;
	}
	user_card.middle = function(){
		var _b = (document.documentElement) ? document.documentElement : document.body;
		var sWidth	= _b.clientWidth;
		var sHeight	= _b.clientHeight;
		var sSrolltop	= _b.scrollTop;
		var sScrollleft	= _b.scrollLeft;
		user_card.obj.style.top		= sHeight/2 - user_card.obj.offsetHeight/2 + sSrolltop + 'px';
		user_card.obj.style.left		= sWidth/2 - user_card.obj.offsetWidth/2 + sScrollleft + 'px';
	}
	user_card.show_card = function(_this, uid){
		this.reset();
		var pos = getXY(_this);
		user_card.obj.style.top = pos.bottom + 'px';
		user_card.obj.style.left = pos.right + 'px';
		user_card.obj.style.width = this.w1;
		user_card.obj.style.height = this.h1;
		user_card.obj.style.display = '';
		if (pos.right + user_card.obj.offsetWidth > user_card.dcmt.clientWidth + user_card.dcmt.scrollLeft){
			user_card.obj.style.left = pos.left - user_card.obj.offsetWidth + 'px';
		}
		if (pos.top + user_card.obj.offsetHeight > user_card.dcmt.clientHeight + user_card.dcmt.scrollTop){
			user_card.obj.style.top = pos.top - user_card.obj.offsetHeight + 'px';
		}
		$("iframe_user_card").src = "http://bbs.service.sina.com.cn/message/user_card.php?uid=" + uid;
	}
	user_card.show_invite = function(toid, c_invite){
		this.reset();
		if (c_invite == '1'){
			show_confirm("对方拒绝好友邀请，是否加到其他联系人中？", "add_contact('" + toid + "')");
			return false;
		}
		user_card.obj.style.width = this.w2;
		user_card.obj.style.height = this.h2;
		user_card.obj.style.display = '';
		this.middle();
		$("iframe_user_card").src = "http://bbs.service.sina.com.cn/message/send_invite.php?uid=" + toid;
	}
	user_card.send_message = function(toid, uname){
		this.reset();
		user_card.obj.style.width = this.w2;
		user_card.obj.style.height = this.h2;
		user_card.obj.style.display = '';
		this.middle();
		$("iframe_user_card").src = "http://bbs.service.sina.com.cn/message/send_msg.php?uid=" + toid + "&uname=" + uname;
	}
	user_card.new_message = function(c){
		this.reset();
		user_card.obj.style.width = this.w3;
		user_card.obj.style.height = this.h3;
		user_card.obj.style.display = '';
		var sWidth	= user_card.dcmt.clientWidth;
		var sHeight	= user_card.dcmt.clientHeight;
		var sSrolltop	= user_card.dcmt.scrollTop;
		var sScrollleft	= user_card.dcmt.scrollLeft;
		user_card.obj.style.top		= sHeight - user_card.obj.offsetHeight + sSrolltop + 'px';
		user_card.obj.style.left		= sWidth - user_card.obj.offsetWidth + sScrollleft + 'px';
		$("iframe_user_card").src = "http://bbs.service.sina.com.cn/message/new_msg.html?" + c;
	}
}
var m = new message();
function ret_1(){
	if (_is_error == "1"){
		_is_error = "发送成功！";
	}
	else if (_is_error == "2"){
		_is_error = "验证码错误！";
		show_win(_is_error, "chg_img()");
		return;
	}
	parent.show_error(_is_error, "");
	parent.user_card.reset()
}
function ret_2(){
	if (_is_error != "1"){
		$("c_invite").innerHTML = _is_error;
		return false;
	}
	$("c_invite").innerHTML = "操作成功！";
}
function ret_3(){
	if (_is_error != "1"){
		return false;
	}
	else if (_m_result.count < 1){
		return false;
	}
	user_card.new_message(_m_result.count);
}
function ret_4(){
	if (_is_error != "1"){
		show_error(_is_error);
		return false;
	}
	reset();
}
function ret_5(){
	if (_is_error != "1"){
		show_error(_is_error);
		return false;
	}
	show_error("填加联系人成功！");
}
function ret_6(){
	if (_is_error != "1"){
		return false;
	}
	else if (_m_result.count < 1){
		return false;
	}
	$("US_MESSAGE").innerHTML = "您有<span style=\"color:#FE0201\">" + parseInt(_m_result.count) + "</span>条未读纸条";
	$("US_MESSAGE").style.display = "";
}
function msg_send_invite(toid, tonick, msg, vcode){
	show_loading();
	if (isNull(msg)){
		show_win("请输入内容");
		return;
	}
	m.set_act("s_invite");
	m.set_val(toid);
	m.set_val(tonick);
	m.set_val(msg);
	m.set_val(vcode);
	m.execute(ret_1);
}
function msg_send(toid, tonick, msg, is_save, vcode){
	show_loading();
	m.set_act("send");
	m.set_val(toid);
	m.set_val(tonick)
	m.set_val(msg);
	m.set_val(is_save);
	m.set_val(vcode);
	m.execute(ret_1);
}
function fri_count(uid, t, func){
	var m = new message();
	m.set_act("f_count");
	m.set_val(uid);
	m.set_val(t)
	m.execute(func);
}
function c_invite(uid){
	m.set_act("c_invite");
	m.set_val(uid);
	m.execute(ret_2);
}
function chk_new_msg(uid){
	if (isNull(uid) || isNaN(uid)){
		return false;
	}
	var m = new message();
	m.set_act("count");
	m.set_val(uid);
	m.execute(ret_3);
}
function chk_new_msg2(uid){
	if (isNull(uid) || isNaN(uid)){
		return false;
	}
	var m = new message();
	m.set_act("count");
	m.set_val(uid);
	m.execute(ret_6);
}
function add_contact(uid){
	m.set_act("add");
	m.set_val(uid);
	m.execute(ret_5);
}
function del_fri(uid, act, type){
	if (isNull(uid) || isNaN(uid)){
		return false;
	}
	if (act){
		show_loading();
		m.set_act("del");
		m.set_val(uid);
		m.set_val(type);
		m.execute(ret_4);
		removeNode($("fri_" + uid));
	}
	else{
		show_confirm("你确认要删除好友吗？", "del_fri('" + uid + "', true, " + type + ")");
	}
}
function add_block(uid){
	if (isNull(uid) || isNaN(uid)){
		return false;
	}
	m.set_act("block");
	m.set_val(uid);
	m.execute(ret_2);
}