function CurrencyFormatted(amount)
{
	var i = parseFloat(amount);
	if(isNaN(i)) { i = 0.00; }
	var minus = '';
	if(i < 0) { minus = '-'; }
	i = Math.abs(i);
	i = parseInt((i + .005) * 100);
	i = i / 100;
	s = new String(i);
	if(s.indexOf('.') < 0) { s += '.00'; }
	if(s.indexOf('.') == (s.length - 2)) { s += '0'; }
	s = minus + s;
	return s;
}

function autotab(original,destination)
{
	if (original.getAttribute&&original.value.length==original.getAttribute("maxlength"))
		destination.focus()
}
function toggleCheck(id)
{
	var checkbox = document.getElementById(id);
	
	if(checkbox.checked == true)
		checkbox.checked = false;
	else
		checkbox.checked = true;
}

function _xmlfetch(xmlobj,tag_name,item_id)
{
	try
	{
		return xmlobj.getElementsByTagName(tag_name).item(item_id).firstChild.data;
	}
	catch(e)
	{
		return '';
	}
}

function $ES(selector,filter)	// Clone of the Mootools Dom Element Selector Function (Because I love mootools so much!)
{
	var list = (document.getElementById(filter) || document).getElementsByTagName(selector);
	var new_list = new Array();
	
	for(var x = 0; x < list.length; x ++)
	{
		new_list[new_list.length] = list[x];
	}
	
	return new_list;
}

String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}
String.prototype.ltrim = function() {
	return this.replace(/^\s+/,"");
}
String.prototype.rtrim = function() {
	return this.replace(/\s+$/,"");
}

// Get the currently pressed keycode (cross-browser)
function pressKey(e)
{
	var code;
	if (!e) var e = window.event;
	if (e.keyCode) code = e.keyCode;
	else if (e.which) code = e.which;
	
	return code;
}

var optionUtils = {
	add: function(value,text,select_id,selected)
	{
		if(selected == null)
			selected = false;
		
		var new_option = document.createElement('option');
		var select = document.getElementById(select_id);
		
		new_option.text = text;
		new_option.value = value;
		new_option.selected = selected;
		
		try	// Mozilla Firefox (Standards Compliant)
		{
			select.add(new_option,null);
		}
		catch(e) // IE 6 Support
		{
			select.add(new_option);
		}
	},
	clear: function(select_id)
	{
		document.getElementById(select_id).innerHTML = '';
	}
}
