//chat 中的js尽可能单独写在这里
//about:c114.html
//======================消息的发送、接收、刷新=================
//发送消息
function sendMessage(){	
	var msg = encodeURIComponent(HTMLEnCode(document.getElementById('writeBoard').value));
	if(msg==''){	//没有消息不做任何操作
		return false;
	}
	var http =new Http;
	http.sURL = 'chat_action.php';
	http.sURL += '?action=1';
	http.sURL += '&message='+msg;	
	http.get(getMessage);
	setTimeout(getReply,4000);
}
function getReply(){	
	var http =new Http;
	http.sURL = 'chat_action.php';
	http.sURL += '?action=11';
	http.get(getMessage);
}
//接受所发送的消息
function getMessage(http){
	if(http.readyState == 4){
		document.getElementById('prompt').innerHTML = '&nbsp;';
		document.getElementById('writeBoard').value	= '';
		refreshMessage(http.responseText);
	}
}
//刷新消息
function refreshMessage(message){
	var msgBoard  = document.getElementById('messageBoard');
	var messageDIV = document.getElementById('messageDIV');
	msgBoard.innerHTML += message;	//不用innerText是为了兼容firfox
	messageDIV.scrollTop = messageDIV.scrollHeight;
}

//======================不定时清理信息=====================
//如果消息无节制地网内存里放，后果将是难以想象的
function clrMessageBoard(){
	//如何判断该收集垃圾了
}

//======================图片上传选择处理===================
function showSelectImgPanal(){
	try{
		var sharePicturePanal = getObject('sharePicturePanal');	//共享图片面板
		var introducePanal = document.getElementById('introducePanal');
		var selectImgPanal = document.getElementById('selectImgPanal');
		hidObject(sharePicturePanal);
		hidObject(introducePanal);
		showObject(selectImgPanal);
	}catch(e){}
}

//======================显示用户头像=====================
function showPhoto(tr){
	var photo = tr.photo;
	if(photo!='nophoto'){
		var img = document.getElementById('photoimg');
		var photodiv = document.getElementById('photodiv');
		img.src = photo;
		photodiv.style.visibility = 'visible';
	}
}
function hidPhoto(){
	document.getElementById('photodiv').style.visibility = 'hidden';
}

//======================显示安装提示界面=====================
function showSetupPanal(){
	var chattingBottom = document.getElementById('chattingBottom');
	var setupPanal = document.getElementById('setupPanal');
	setupPanal.style.display = '';	//显示安装提示面板
	chattingBottom.style.display = 'none';	//隐藏聊天时的面板
}
function cancelSetup(){
	var setupPanal = document.getElementById('setupPanal');
	var setupOverPanal =  document.getElementById('setupOverPanal');
	var chattingBottom = document.getElementById('chattingBottom');
	setupOverPanal.style.display = 'none';	//隐藏安装完成面板
	setupPanal.style.display = 'none';	//隐藏安装提示面板
	chattingBottom.style.display = '';	//显示聊天时的面板
}
//
function icrSetup(){	//安装完成
	var setupOverPanal =  document.getElementById('setupOverPanal');
	var setupPanal = document.getElementById('setupPanal');
	setupOverPanal.style.display = '';			//显示安装完成面板
	setupPanal.style.display = 'none';			//隐藏安装面板
}

//========================保存消息=========================
function saveMessage(){
	try{
		//保存消息，清理消息板	
		var messageBoard = document.getElementById('messageBoard');
		var message = br2nl(messageBoard.innerHTML).stripHTML();	//stripHTML方法在commom.js里定义了
		var doc = parent.hidIframe.document;
		doc.charset = 'utf-8';		//页面里指定的话，这里可以省略
		doc.body.innerText = message;
		if(doc.execCommand('Saveas',false,'%USERPROFILE%\\My documents\\1c.txt')){
			messageBoard.innerHTML = '';	
		}
		doc.body.innerText = '';
	}catch(e){alert(e);}
}
//==========================================================

function refreshSharePicture(picture){
	var sharePicture = getObject('sharePicture');	//共享图片
	sharePicture.src = picture;
}

//===========================================================
//请求在线用户
function requestOnlineUsers(){
	var http = new Http;		
	http.sURL = 'chat_action.php?action=2';	
	http.get(receiveOnlineUsers);	
}
//接受在线用户
function receiveOnlineUsers(http){
	if(http.readyState == 4){
		if(http.status==200){
			refreshOnlineUsers(http.responseText);	
		}else{
			requestOnlineUsers();
		}
	}				
}
function refreshOnlineUsers(onlineUsers){
	var userPanal = document.getElementById('userPanal');
	userPanal.innerHTML = onlineUsers;	
}
function init(){
	requestOnlineUsers();
	refreshSharePicture('/chat/temp_image/chat_sharePicture_sample.jpg');
}
window.onload = init;

