

// JavaScript File



var loadingIndicator = new Image();
loadingIndicator.src = "/appchat/images/loading.gif";

var idleIndicator = new Image();
idleIndicator.src = "/appchat/images/idle.gif";

function ShowMessageWindow(message)
{
	var messageWindow = Get("MessageWindow");
	var messageContent = Get("MessageWindowContent");
	var chatWindow = Get("ChatContainer");
	
	messageContent.innerHTML = message;

	messageWindow.className = "MessageWindow";
	
	messageWindow.style.width = "300px";
	//messageWindow.style.height = "200px";
	
	messageWindow.style.left = ((FindPosX(chatWindow) + (chatWindow.offsetWidth / 2)) - (messageWindow.offsetWidth / 2)) + "px";
	messageWindow.style.top = ((FindPosY(chatWindow) + (chatWindow.offsetHeight / 2)) - (messageWindow.offsetHeight / 2)) + "px";
}

function HideMessageWindow()
{
	var messageWindow = Get("MessageWindow");

	messageWindow.className = "Hidden";
	
	messageWindow.style.width = "1px";
	messageWindow.style.width = "1px";
	
	messageWindow.style.left = "1px";
	messageWindow.style.top = "1px";
	
	try
	{
		Get("InputMessage").focus();
	}
	catch (e) { }
}

function ShowLoadingIndicator()
{
    Get("LoadingIndicator").innerHTML = "<img src=\"" + loadingIndicator.src + "\" width=\"16\" height=\"16\" alt=\"Updating Content\" align=\"absmiddle\" />";
}

function HideLoadingIndicator()
{
    Get("LoadingIndicator").innerHTML = "<img src=\"" + idleIndicator.src + "\" width=\"16\" height=\"16\" alt=\"Idle\" align=\"absmiddle\" />";
}

function HandleRedirects(updateString)
{
    if (updateString == null || updateString.length == 0)
        return;

    var redirects = updateString.split("[split]");
    
    for (var r=0; r < redirects.length; r++)
    {
        if (redirects[r] != null && redirects[r].length > 0)
            document.location.href = redirects[r];
    }
}

function HandleInvitations(updateString)
{
    if (updateString == null || updateString.length == 0)
        return;
    
    var invitations = updateString.split("[split]");
    
    for (var i=0; i < invitations.length; i++)
    {
        if (invitations[i] != null && invitations[i].length > 0)
        {   
            try
            {
                var inviteParts = invitations[i].split("|**|");
                
                var inviterID   = inviteParts[0];
                var inviterName = inviteParts[1];
            
                var inviteHtml = "";
                
                inviteHtml += "<div class=\"MediumHeader\">Private Chat Invitation:</div>";
                inviteHtml += "You have been invited to chat privately with " + inviterName + ".<br /><br />";
                inviteHtml += "<div align=\"center\">";
                inviteHtml += "<a href=\"javascript:LaunchPrivateChat(" + inviterID + ");\" onclick=\"LaunchPrivateChat(" + inviterID + ");HideMessageWindow();return false;\">";
                inviteHtml += "Accept " + inviterName + "'s Invitation";
                inviteHtml += "</a>";
                inviteHtml += "</div>";
            
                ShowMessageWindow(inviteHtml);
            }
            catch (e) { }
        }
    }
}

function ShowConnectionError()
{
    var errorHtml = "";
    
    errorHtml += "<div class=\"MediumHeader\">Connection Error:</div>";
    errorHtml += "The chat software is having trouble connecting to the server.<br /><br />";
    errorHtml += "You can ignore this error, and the software will automatically keep trying to reconnect. ";
    errorHtml += "If this error continues, it may help to refresh the page.<br /><br />";
    errorHtml += "<a href=\"javascript:window.location.reload(true);\">Refresh The Page</a>";

    ShowMessageWindow(errorHtml);
}