loadscript("mdialog");

function pmsg(recvuid, subject) {
	$.post(getUrl('member')+'index.php', { ac:"pm", op:'write', recvuid:recvuid, subject:subject, in_ajax:1 }, 
		function(result) {
			if(result.match(/\{\s+caption:".*",message:".*".*\s*\}/)) {
				myAlert(result);
			} else {
				dlgOpen('发送短信', result, 480, 360);
			}
		});
}

function checkpm () {
	var form = document.getElementById('pmform');
	
	if(form.recv_users.value == ''){
		msgOpen('未添加收件人!');
		return false;
	} else if(form.subject.value == '') {
		msgOpen('未填写短信标题!');
		return false;
	} else if(form.subject.value.length > 60) {
		msgOpen('短信标题不能超过60个字符!');
		return false;
	} else if(form.content.value == '') {
		msgOpen('未填写短信内容!');
		return false;
	} else if(form.content.value.length > 500) {
		msgOpen('短信内容不能超过500个字符!');
		return false;
	}
	return true;
}

function readmsg(pmid) {
	var c = $("#pmid_"+show_pmid+'_content');
	if(c[0]) {
		c.css("display","none");
	}
	var n = $("#pmid_"+pmid+'_content');
	if(n[0]) {
        c.css("display","");
		show_pmid = pmid;
		return;
	}

	$.post(getUrl('member')+'index.php', {ac:"pm", in_ajax:1, op:'read', pmid:pmid }, 
		function(result){
			if (result.match(/<.+id="readmsg".*>/)) {
				var c_row = document.getElementById('pmid_'+pmid);
				var m_table = c_row.parentNode;
				var n_row = m_table.insertRow(c_row.rowIndex + 1);
				n_row.id = 'pmid_'+pmid+'_content';
				var n_cell1 = n_row.insertCell(0);
				n_cell1.innerHTML = '&nbsp;';
				var n_cell2 = n_row.insertCell(1);
				n_cell2.colSpan = 4;
				n_cell2.innerHTML = result;
				show_pmid = pmid;
			} else {
				myAlert(result);
			}
	});
}

function addfriend(friendid) {
	$.post(getUrl('member')+'index.php', { ac:"friends",in_ajax:1,op:'add',friendid:friendid }, 
		function(result){
			if (result.match(/<form.+method="post".+>/)) {
				result += '<iframe style="display:none" src="" name="ifaddfriend" id="ifaddfriend"></iframe>';
				dlgOpen('添加好友', result, 380, 290);
			} else {
				myAlert(result);
			}
	});
}

function post_addfriend() {
	var form = document.addfriendfrm;
	if(!is_numeric(form.friendid.value)){
		alert('会员不存在，无法添加!');
		return false;
	} else if(form.content.value.length > 300) {
		alert('对好友的留言不能超过300个字，请精简留言!');
		return false;
	}

	return true;
}