var get_ul;
function Load_init(){
		if (frie_uid!=0){sayto(frie_uid);}else{my_getbyid('recv').innerHTML=formatstr('系统提示','请在右边聊天会员选择聊友！');
	my_getbyid('message').disabled=true;
	}
	show_ul('user');
}

function call_me(userid)
{
if (userid!=0){
var ajaxobj=new AJAXRequest;
ajaxobj.method="POST"; 
ajaxobj.url="/httpreq/chat.asp?action=call&userid="+escape(userid);
ajaxobj.callback=function(xmlobj) {
var response = xmlobj.responseText;
setDisplay("load_div",'0');
show_info(response,'400','100');
setTimeout("sdis_play()",3000);
}

}else{setDisplay("load_div",'1');}
}
function call_acc(userid){
	if (userid!=0){
	var ajaxobj=new AJAXRequest;
	ajaxobj.method="POST"; 
	ajaxobj.url="/httpreq/chat.asp?action=accept&t=1&userid="+escape(userid);
	ajaxobj.callback=function(xmlobj) {
	var response = xmlobj.responseText;
		var msg_show=my_getbyid("recv");
		msg_show.innerHTML	+=response;
		msg_show.scrollTop=msg_show.scrollHeight;
	}
ajaxobj.send();	
}
}

function call_ref(userid){
	if (userid!=0){
	var ajaxobj=new AJAXRequest;
	ajaxobj.method="POST"; 
	ajaxobj.url="/httpreq/chat.asp?action=accept&t=2&userid="+escape(userid);
	ajaxobj.callback=function(xmlobj) {
	var response = xmlobj.responseText;
		var msg_show=my_getbyid("recv");
		msg_show.innerHTML	+=response;
		msg_show.scrollTop=msg_show.scrollHeight;
	}
ajaxobj.send();	
}
}

function show_ul(para)
{
	get_ul=para;
	Load_user();
	switch (para)
	{
		case 'user':
			document.getElementById('user').style.display	=	'';
			document.getElementById('inv').style.display	=	'none';
			document.getElementById('beinv').style.display	=	'none';
			break;
		case 'inv':
			document.getElementById('user').style.display	=	'none';
			document.getElementById('inv').style.display	=	'';
			document.getElementById('beinv').style.display	=	'none';
			break;
		case 'beinv':
			document.getElementById('user').style.display	=	'none';
			document.getElementById('inv').style.display	=	'none';
			document.getElementById('beinv').style.display	=	'';
			break;
	}
}

function Load_user(){
var ajaxobj=new AJAXRequest;
ajaxobj.method="POST"; 
ajaxobj.url="/httpreq/chat.asp?action=chat_u&u="+escape(get_ul);
ajaxobj.callback=function(xmlobj) {
var response = xmlobj.responseText;
my_getbyid(get_ul).innerHTML=response;
}
ajaxobj.send();
setTimeout('Load_user()',60000);
}
function sayto(uid){
ajaxobj=new AJAXRequest;
ajaxobj.method="POST"; 
ajaxobj.url="/httpreq/chat.asp?action=chat_getuser&Userid="+escape(uid);
ajaxobj.callback=function(xmlobj) {
var response = xmlobj.responseText.split("|||");
if (response[4]==''){
my_getbyid('recv').innerHTML="";
my_getbyid('message').disabled=false;
my_getbyid('f_userid').value=response[0];
my_getbyid('nick').innerHTML="<b><a href=/html/"+response[2]+" target=_blank>"+response[1]+"</a></b>";
my_getbyid('black_link').href="javascript:call_ref("+response[0]+")";
my_getbyid('pic_link1').href="/html/"+response[2]+"";
my_getbyid('pic_link2').href="/other/album/user.html?userid="+response[0]+"";
my_getbyid('pic_link3').href="/other/diary/list.html?keyWord="+response[1]+"&Type=1";
my_getbyid('pic_link4').href="/my/usersms.asp?action=new&Userid="+response[0]+"";
if (response[3]!=''){
my_getbyid('uface').innerHTML="<img src=/html/"+response[3]+">";
}else{my_getbyid('uface').innerHTML="<img src=/chat/nopic_f.jpg>";}
}else{
	my_getbyid('recv').innerHTML=formatstr('系统提示：',response[4]);
	my_getbyid('f_userid').value=0;
	my_getbyid('message').disabled=true;
	}
}
ajaxobj.send();
Get_inv_msg();
}

function send(){
	var f_userid=my_getbyid('f_userid').value;
	if (!(f_userid>0))
	{
		alert('请选择要发送的会员');
		return false;
	}
	var message_obj=my_getbyid("message");
	if(	message_obj.disabled)
	{
		alert('请等待对方接受你的邀请');
		return false;		
	}
	var message=message_obj.value;
	message_obj.focus();
	if(message	==	'')
	{
		alert('请输入信息');
		message_obj.focus();
		return false;
	}

	var message_tmp	=	message;
	var msg_show=my_getbyid("recv");
	msg_show.innerHTML	+=	formatstr(self_name,message_tmp);
	msg_show.scrollTop=msg_show.scrollHeight;
	message_obj.value='';
	var url="/httpreq/chat.asp?action=chat_send&userid="+f_userid+"&message="+encodeURIComponent(message);
	var ajaxobj=new AJAXRequest;
	ajaxobj.method="POST"; 
	ajaxobj.url=url;
	ajaxobj.callback=function(xmlobj) {
	var response = xmlobj.responseText;
		msg_show.innerHTML	+=response;
		msg_show.scrollTop=msg_show.scrollHeight;
	}
	ajaxobj.send();
	Get_inv_msg();
}

function get_date(){
var now = new Date();
var yy = now.getYear();
var mm = now.getMonth()+1;
var dd = now.getDate();
 //取时间 
var hh = now.getHours(); 
var mi = now.getMinutes();
var ss=(now.getSeconds()<10)?("0"+now.getSeconds()):(now.getSeconds());
var clock=yy+"-";clock+=mm+"-";clock+=dd+" ";clock+=hh+":";clock+=mi+":";clock+=ss;
return clock;
}
function formatstr(name,str){
	var message_tmp=str;
	while(message_tmp.indexOf('\n')	>=	0)
	{
		message_tmp	=  message_tmp.replace('\n','<br />');
	}
	var msg_str='<div class=memsg><h1><b>'+name+'：</b>&nbsp;&nbsp;'+get_date()+'</h1>'+message_tmp+'</div>';
	return msg_str;
}

function Get_inv_msg(){
	var f_userid=my_getbyid('f_userid').value;
	var ajaxobj=new AJAXRequest;
	ajaxobj.method="POST"; 
	ajaxobj.url="/httpreq/chat.asp?action=chat&userid="+f_userid;
	ajaxobj.callback=function(xmlobj) {
	var response = xmlobj.responseText;
		if(response!=''){
		var msg_show=my_getbyid("recv");
		msg_show.innerHTML	+=response;
		msg_show.scrollTop=msg_show.scrollHeight;
		}
		setTimeout('Get_inv_msg()',8000);
	}
	ajaxobj.send();
}