

// JavaScript File



var safeTimer;
var errorBuildup = 0;
var errorsToAlert = 10;

function Get(elemID)
{
	return document.getElementById(elemID);
}

function FindPosX(obj)
{
	var curleft = 0;
	if(obj.offsetParent)
		while(1)
		{
			curleft += obj.offsetLeft;
			if(!obj.offsetParent)
				break;
			obj = obj.offsetParent;
		}
	else if(obj.x)
		curleft += obj.x;
	return curleft;
}

function FindPosY(obj)
{
	var curtop = 0;
	if(obj.offsetParent)
		while(1)
		{
			curtop += obj.offsetTop;
			if(!obj.offsetParent)
				break;
			obj = obj.offsetParent;
		}
	else if(obj.y)
		curtop += obj.y;
	return curtop;
}

function FadeOpacityIn(elem, time)
{
    var steps = time / 100;
    var delta = 100 / steps;
    
    FadeOpacityStep(elem, 0, steps, delta, time);
}

function FadeOpacityOut(elem, time)
{
    var steps = time / 100;
    var delta = -1 * (100 / steps);
    
    FadeOpacityStep(elem, 0, steps, delta, time);
}

function FadeOpacityStep(elem, stepNum, steps, delta, time)
{
    if (delta > 0)
        SetOpacity(Get(elem), (delta * stepNum));
    else
        SetOpacity(Get(elem), 100 + (delta * stepNum));
    
    if (stepNum < steps)
        setTimeout("FadeOpacityStep('" + elem + "', " + (stepNum+1) + ", " + steps + ", " + delta + ", " + time + ");", (time / steps));
}

function SetOpacity(elem, opacityAsInt)
{
	if (opacityAsInt < 1)
	{
		// fixes IE7 bug - text rendering loses style, anti-alias if opacity hits 0 on an element
		opacityAsInt = 1;
	}
	
	elem.style.opacity = (opacityAsInt / 100);
	elem.style.filter  = "alpha(opacity=" + opacityAsInt + ")";
}

function SubmitOnEnter(e, actionToDo)
{
	var keynum;
	var keychar;

	if(window.event) // IE
	{
		keynum = e.keyCode
	}
	else if(e.which) // Netscape/Firefox/Opera
	{
		keynum = e.which
	}

	if (keynum == 13)
	{
		actionToDo();
		return false;
	}
	
	return true;
}

function SetUpdating()
{
    safeTimer = setTimeout("SetError();SetIdle();", 4000);

    isUpdating = true;
    ShowLoadingIndicator();
}

function SetIdle()
{
    clearTimeout(safeTimer);

    isUpdating = false;
    HideLoadingIndicator();
    
    if (errorBuildup > 0)
        errorBuildup -= 1;
}

function SetError()
{
    errorBuildup += 2;
    
    if (errorBuildup >= errorsToAlert)
    {
        errorBuildup = 0;
        ShowConnectionError();
        lastMessageID = -1;
    }
}

function ChatFontSizeAdjust(adjustment)
{
	currentFontSize += adjustment;

	if (currentFontSize < 7)
		currentFontSize = 7;

	if (currentFontSize > 19)
		currentFontSize = 19;

	Get("ChatWindow").style.fontSize = currentFontSize + "px";
}

function nothing() { }