function endsWith(str, suff)
{
	return str.indexOf(suff) == str.length - suff.length;
}
 
function closeFrame(name)
{
	if (!top[name])
		return;

	top[name].document.open();
	top[name].document.close();
}

function formFocus(frm)
{
	var elems = frm.elements;
	for (var e = 0; e < elems.length; e++)
	{
		if (elems[e].type == "text")
		{
			elems[e].focus();
			return;
		}
	}
}

function toggleDisplay(id)
{
	var element = document.getElementById(id);
	element.style.display = element.style.display == "block" ? "none" : "block";
	element.style.zIndex = 10;
}

function addOption(select, text, value)
{
	select.options[select.options.length] = new Option(text, value);
}

function removeSelected(select)
{
	for (var o = select.options.length - 1; o >= 0; o--)
		if (select.options[o].selected)
			select.options[o] = null;
}

function selectAll(select, selected)
{
	for (var o = 0; o < select.options.length; o++)
		select.options[o].selected = selected;
}

function getSelected(sel)
{
	try
	{
		if (sel.selectedIndex == -1)
			return null;
		return sel.options[sel.selectedIndex];
	}
	catch(e)
	{
		alert("error.common.jsp.getSelected()\n" + e + " - " + e.description);
	}
}

function pleaseWait(frame, context, evalStr)
{
	frame.location.href = context + "/PleaseWait.do";
	window.setTimeout(evalStr, 500);
}

function check(checkbox, hiddenName)
{
	checkbox.form.elements[hiddenName].value = checkbox.checked;
}

var NUMERIC = "0123456789";
function checkKey(accept, e)
{
	try
	{
		e = e ? e : window.event;
		var code = e.charCode ? e.charCode : e.keyCode;
		
		if (code == 0 || code == 8 || code == 9 || code == 13 || code == 16 || code == 17 || code == 18 || code == 27 || code == 46 || code == 91)
			return true;
		return accept.indexOf(String.fromCharCode(code)) != -1;
	}
	catch(e)
	{
		alert("error.common.js.checkKey()\n" + e + " - " + e.description);
	}
}

function sum2DP(f1, f2)
{
	try
	{
		var ROUND_FACTOR_2DP = 100;
		return (Math.round(f1 * ROUND_FACTOR_2DP) + Math.round(f2 * ROUND_FACTOR_2DP)) / ROUND_FACTOR_2DP;
	}
	catch(e)
	{
		alert("error:common.js.parseInteger()\n" + e + " - " + e.description);
	}
}
	
function parseInteger(src)
{
	try
	{
		return Math.round(parseFloat(src));
	}
	catch(e)
	{
		alert("error:common.js.parseInteger()\n" + e + " - " + e.description);
	}
}