function handleMessage(aJSJaCPacket) {
		now = new Date();
		var mtime = (now.getHours()<10)? "0" + now.getHours() : now.getHours();
		mtime += ":";
		mtime += (now.getMinutes()<10)? "0" + now.getMinutes() : now.getMinutes();
		mtime += ":";
		mtime += (now.getSeconds()<10)? "0" + now.getSeconds() : now.getSeconds();

    chatW.putMsgHTML(htmlEnc(aJSJaCPacket.getBody()),
						mtime,
						aJSJaCPacket.getFrom().substring(0,aJSJaCPacket.getFrom().indexOf('@')),
						"red");
}

function handleConnected() {
//	alert('connected');
	con.send(new JSJaCPresence());
}

function handleDisconnect() {
	alert('disconnected');
}

function handleConError(e) {
	switch (e.getAttribute('code')) {
	case '401':
		alert("Authorization failed");
		if (!con.connected())
			window.close();
		break;
	case '409':
		alert("Registration failed!\n\nPlease choose a different username!");
		break;
	case '503':
		alert("Service unavailable");
		break;
	case '500':
		if (!con.connected())
			if (confirm("Internal Server Error.\n\nDisconnected.\n\nReconnect?"))
				changeStatus(onlstat,onlmsg);
		break;
	default:
		alert("An Error Occured:\nCode: "+e.getAttribute('code')+"\nType: "+e.getAttribute('type')+"\nCondition: "+e.firstChild.nodeName); // this shouldn't happen :)
		break;
	}
}

function handleEvent(aJSJaCPacket) {
	alert("IN (raw):<br/>" +htmlEnc(aJSJaCPacket.xml()) + '<hr noshade size="1"/>');
}

function handlePresence(aJSJaCPacket) {
		alert('<b>'+aJSJaCPacket.getFrom()+' has become available.</b>');
}
