// GO-Global JavaScript Interface

var callbackLoopRunning = 0;
var callbackFrequency = 200; // sets the frequency of call to check for new messages

// Required function
function EnterCallbackLoop()
{
	if (!callbackLoopRunning)
  	{
  	    callbackLoopRunning = 1;
  	    document.getElementById(RAPIDX_CONTROL_NAME).ResetMessageProcessor();
  		CallbackLoop();
	}
}

// Required function
function CallbackLoop()
{
	document.getElementById(RAPIDX_CONTROL_NAME).MessageProcessor();
	setTimeout("CallbackLoop()", callbackFrequency);
}

// Required function
function ReturnValue(value)
{
	if (browser.firefox || browser.chrome)
	{ 
		return document.getElementById(RAPIDX_CONTROL_NAME).ReturnMessage(value);
	}
	else
	{
		return value;
	}
}

// Optional function
function ConnectionOpened()
{
	//alert("Connection Opened");
	return ReturnValue();
}

// Optional function
function ConnectionClosed()
{
	//alert("Connection Closed");
	return ReturnValue();
}

/////////////////////////////////////////////////////////////////////////////////////

// The functions below are provided as examples, they can be removed or modified as necessary.

function JavaScriptAlert()
{
	var outputString = "";

	for (var i = 0; i < arguments.length; i++)
	{
		outputString += arguments[i] + " ";
	}

	return ReturnValue(alert(outputString));
}

function JavaScriptConfirm()
{
	var outputString = "";

	for (var i = 0; i < arguments.length; i++)
	{
		outputString += arguments[i] + " ";
	}

	return ReturnValue(confirm(outputString));
}

function JavaScriptPrompt()
{
	var outputString = "";
	var defaultValue = 0;

	for (var i = 0; i < arguments.length; i++)
	{
		if (i == 0)
		{
			defaultValue = arguments[i];
		}
		else
		{
			outputString += arguments[i] + " ";
		}
	}

	return ReturnValue(prompt(outputString, defaultValue));
}

function JavaScriptAdd()
{
	var retVal = 0

	for (var i = 0; i < arguments.length; i++)
	{
		retVal += parseInt(arguments[i]);
	}

	return ReturnValue(retVal);
}

function JavaScriptStrlen()
{
	var totalStringLength = 0;

	for (var i = 0; i < arguments.length; i++)
	{
		totalStringLength += arguments[i].length;
	}

	return ReturnValue(totalStringLength)
}

