﻿
function initChat()
{
 //get chat log and setup timer
 getChatLog();
 var txtBox = document.getElementById("ctl00__msg")
 if (txtBox) txtBox.onkeydown = chatKeyDown;
}

function chatKeyDown(e)
{
	if (!e)
		var e = window.event

	var code = e.keyCode
  if (code == 13) {
	 var btn = document.getElementById("_chatBtn");
	 if (btn)
	 {
		btn.click();
	 }
	 return false;
  }
}

function sendChatMsg(playerid,color)
{
 //send chat message
  var msgControl = document.getElementById("ctl00__msg");
  if (!msgControl) return;
  if (msgControl.value=="Type to Chat") return;
  var to = "";
	StratEngineWS.Chat.SendChat(0,playerid,to,msgControl.value,color,sendChatSuccess,sendChatError);
	msgControl.value = "Type to Chat";
	msgControl.blur();
}

function getChatLog()
{
 StratEngineWS.Chat.GetFormattedChatContent(0,getChatLogSuccess,getChatLogError);
 setTimeout("getChatLog();",2500);
}

function getChatLogSuccess(result, methodName)
{

	var rd = document.getElementById("_chatBox");
	if (rd)
	{
	 rd.innerHTML = result;
	 rd.scrollTop = rd.scrollHeight;
	}
}

function getChatLogError(error)
{
 setTimeout("getChatLog();",2500);
}

function sendChatSuccess(result,methodName)
{
}

function sendChatError(error)
{
}
