function chat_send()
{
	var jmsg=compose_jmsg(['marijn@mybox7']);
	jmsg.params='&to='+rcpts_as_param(jmsg.to)+'&subject='+xescape('SurgeChat')+'&send_mode=plain_text';
	jmsg.msg_html=dge('chat_input').value;
	jmsg.chat=true;
	ajax_send(jmsg);
}

function surge_chat_init()
{
#	return;
	dge('online_indicators').innerHTML=
		 '<div id="oli1" style="background:#ffda49;padding:2px;position:absolute;left:10px;top:10px;border:1px solid #999;" onclick="do_chat()">'
		+'<img src="/surgeweb/shared/img/mugshot.jpg" height=34 width=34 style="border:1px solid #999;background:white;"'
	 	+'</div>'
	 	+'<div id="oli2" style="background:#ffda49;padding:2px;position:absolute;left:10px;top:10px;border:1px solid #999;" onclick="do_chat()">'
		+'<img src="/surgeweb/shared/img/mugshot.jpg" height=27 width=27 style="border:1px solid #999;background:white;">'
	 	+'</div>'
	 	+'<div id="oli3" style="background:#ffda49;padding:2px;position:absolute;left:10px;top:10px;border:1px solid #999;" onclick="do_chat()">'
		+'<img src="/surgeweb/shared/img/mugshot.jpg" height=22 width=22 style="border:1px solid #999;background:white;">'
	 	+'</div>';

}
function chat_reposition()
{
	xx['link_bar_w']=dge('link_bar').offsetWidth;
#		Small status indicator	
	el=dge('oli3');
	el.style.top=px(xx['ban_h']-el.offsetHeight-4);
	el.style.left=px(xx['screen_ww']-xx['link_bar_w']-5);
# Bigger status indicator
	el=dge('oli1');
	el.style.top=px(xx['ban_h']-el.offsetHeight-6);
	el.style.left=px(xx['screen_ww']-xx['link_bar_w']-el.offsetWidth-10);
	el=dge('oli2');
	el.style.top=px(xx['ban_h']-el.offsetHeight-9);
	el.style.left=px(xx['screen_ww']-xx['link_bar_w']-el.offsetWidth-55);
	el=dge('personal_info');
	el.style.left=px(xx['screen_ww']-el.offsetWidth-35);
	x=dge('msg_headers');
	el.style.top=px(dge('sizer2').offsetTop+(x?x.offsetHeight:0)+23);
}
function chat_window()
{	
	return dge('chat_window').childNodes[sw.chat_pane];
}
function set_chat_view(type)
{
	if(type=='message'){
#		class_add(dge('chat_list'),'hidden');
		class_remove(dge('chat_message'),'hidden');
		class_remove(dge('chat_list'),'hidden');
		class_remove(dge('chat_reply'),'hidden');
		sw.chat_pane=0;
	}else{
		class_remove(dge('chat_list'),'hidden');
#		class_add(dge('chat_message'),'hidden');
		class_remove(dge('chat_reply'),'hidden');
		sw.chat_pane=1;
	}
	do_resize_real()
}



function chat_uid(msg_id)
{
	do_chat('message', 42, 'Ralph');
}

function do_chat(type, fibble, chat_user)
{
	if (!chat_user) chat_user='ChrisP';
	sndReq('cmd=show&page=~chat.htm&sort=date&rev=false&fld_id=@ Chat&chat_user='+chat_user+'&'+(type?'&chat_view='+type:'')+iid()+'&fibble='+fibble, function(chan){
	node=actionReqSethtml(chan.responseText,'utility');
		var o=chat_window();
		o.scrollTop=o.scrollHeight;
	});
}
function chat_pending(count)	// cf select_mailbox_all
{
	var ex=dge('chat_pending');
	class_remove(ex,'hidden');
	ex.innerHTML='<a href="#">'+count+' Chat messages pending</a>';
}

function resize_chat(xx)
{
	el=chat_window();
	if(el){
		el.style[htype]=px(xx['cc_h']-240);
#		el=dge('chat_qreply');
#		el.style.width=px(xx['cc_w']-22);
	}

}

function chat_btn(id)
{
	if(id==1);
		chat_show_message(417);
		
		chat_state('reply');
}



#ChatEngine