var newWin;
function open_window(docUrl, windowName, width, height, windowOpts)
{
	if(windowOpts == undefined) windowOpts = 'status=no,toolbar=no,location=no,menubar=no,scrollbars=yes,resizable=yes';
	newWin = window.open(docUrl, windowName, windowOpts + ',width=' + width + ',height=' + height);
	if (!newWin.opener) newWin.opener = self;
	if (newWin.resizeTo)
	{
		newWin.resizeTo(width, height);
	}
	else
	{
		// no resizeTo method; we must close and open the window at the specified size
		newWin.close();
		window.setTimeout("newWin = window.open('" + docUrl + "', '" + windowName + "', '" + windowOpts + ",width=" + width + ",height=" + height + "');", 50);
	}
	newWin.location = docUrl;
	newWin.focus();
}

function openerLocation(page)
{
	if ( arguments.length > 1 )
	{
		closeWindow = arguments[1];
	}
	else
	{
		closeWindow = true;
	}

	if (window.opener && !window.opener.closed)
	{
		window.opener.location = page;
	}
	else
	{
		newWin = window.open(page);
		window.opener = newWin;
	}
	window.opener.focus();
	if (closeWindow == true) window.close();
}

function window_status(text)
{
	window.status = text;
	// work around for IE5 bug
	window.setTimeout('window.status="' + text + '"', 50);
	return true;
}

/**
 * Double-click prevention
 * @note should be called like:
 * [form action="index.html" method="post" onsubmit="click_check()"]
 */
var click_count = 0;
var reset_timeout = 3;
var reset_counter = reset_timeout;
var reset_counter_started = false;
function reset_click_count()
{
	reset_counter_started = true;
	// reset click_count every reset_timeout seconds
	reset_counter -= 1;
	if (reset_counter != -2) {
		if (reset_counter <= 0) {
			click_count = 0;
			reset_counter = reset_timeout;
			reset_counter_started = false;
		} else {
			setTimeout('reset_click_count()', 1000);
		}
	}
}
function click_check()
{
	// override reset_timeout with optional argument to click_check
	// -1 is a special value which will never allow the form to be submitted twice
	if (arguments.length > 0)
		reset_timeout = arguments[0];
	if (click_count == 0) {
		click_count++;
		reset_counter = reset_timeout;
		// start the countdown
		if (reset_counter_started == false)
			setTimeout('reset_click_count()', 1000);
		return true;
	} else {
		return false;
	}
}
function clear_click_count()
{
	click_count = 0;
	reset_counter_started = false;
}

function fillText(strText,objFormField)
{
	// adds or appends content to textarea
	objFormField.value+=strText;
}

var formSubmitted = false;
function enter_key_trap(e)
{
	var keyPressed;
	if(navigator.appName == "Microsoft Internet Explorer")
	{
		keyPressed = window.event.keyCode;
	}
	else
	{
		keyPressed = e.which;
	}
	if((keyPressed == 13 || String.fromCharCode(keyPressed) == "\n" || keyPressed == 10) && !formSubmitted)
	{
		document.autosubmit.submit();
	}
}
function capture_keys( field_to_focus )
{
	if ( window.document.autosubmit )
	{
		window.document.autosubmit.onsubmit = function() { formSubmitted = true; }
		if ( field_to_focus != null )
		{
			window.document.autosubmit[field_to_focus].focus();
		}
		if (window.document.captureEvents != null)
		{
			// Setup the enter keytrap code
			window.document.captureEvents(Event.KEYPRESS);
			window.document.onkeypress = enter_key_trap;
		}
	}
}
