/**
 * TODO:  Namespace everything
 */

function jsVersion()
{
	return "0.2";
}

function isReplAtMainWindow()
{
	if (this.SeleniumIDE && this.SeleniumIDE.Loader)
		return true;
	else 
		return false;
}

isReplAtMainWindow.Doc = 
	"Returns the first instance of the Selenium Ide editor.\n " +
	"It's a bit of a hack, but this seems to be the best way I can figure out how to do it so far." ;

function isReplAtSeleniumWindow()
{
	if (this.selenium && this.SeleniumError && this.editor)
		return true;
	else
		return false;
}

function getSeleniumIde()
{
	if (isReplAtMainWindow())
		return this.SeleniumIDE.Loader.getEditors()[0];
	else if (isReplAtSeleniumWindow())
		return this.editor;
	else
		return false;
}

/**
 * Returns the debugger 
 */
function getSeleniumIdeDebugger()
{
	var ide = getSeleniumIde();
	if (ide)
		return ide.selDebugger;
	else
		return false;
}

/**
 * Plays the current test inside of selenium
 */
function playCurrentTest()
{
	getSeleniumIdeDebugger().start();
}

/**
 * Return the result of the selenium test
 */
function getTestResult()
{
	return (! getSeleniumIde().testCase.debugContext.failed);
}

/**
 * Tell us if the selenium test is running
 */
function isTestRunning()
{
	return getSeleniumIde().testCase.debugContext.started;
}

/**
 * Serialize data for emacs
 * This could be done better.  Much better.  Right now it just does what it needs to.
 */
function selenemacsize(input)
{
	return "(selenemacs " + (input ? "true" : "false") + ")";
}