
function clear_if(default_text, input)
{
	if (input.value == default_text)
	{
		input.value = "";
		input.style.color = "#000000";
	}
}

function set_default(default_text, input)
{
	if (input.value == "")
	{
		input.value = default_text;
		input.style.color = "#999999";
	}
}

function show_help(input)
{
	var callout = document.getElementById(input.id + "-help");
	var dim = get_abs_top_left(input);
	callout.style.left = dim.left + 'px';
	callout.style.top = dim.top - input.offsetHeight + 'px';
	callout.style.visibility="visible";
}

function hide_help(input)
{
	var callout = document.getElementById(input.id + "-help");
	callout.style.visibility = "hidden";
}

function select_all(input)
{
	input.focus();
	input.select();
	input.style.color = "#000000";
}

// http://vishalsays.wordpress.com/2007/12/21/finding-elements-top-and-left-using-javascript/
function get_abs_top_left(elm)
{
	var x, y = 0;
	x = elm.offsetLeft;
	y = elm.offsetTop;
	elm = elm.offsetParent;

	while(elm != null)
	{
		x = parseInt(x) + parseInt(elm.offsetLeft);
		y = parseInt(y) + parseInt(elm.offsetTop);
		elm = elm.offsetParent;
	 }

	return {top:y, left: x};
}

function replace_node_text(id, new_text)
{
	var node = document.getElementById(id);
	while (node.firstChild)
	{
		node.removeChild(node.firstChild);
	}
	node.appendChild(document.createTextNode(new_text));
}

function random_monies()
{
	Array.prototype.choose = function ()
	{
		return this[Math.floor(Math.random() * this.length)];
	};

	return ["dineros", "bucks", "dosh", "scrillas", "paypas", "lollies", "readies", "quids", "scratch", "cheeze"].choose();
}


//window.onload = function() { replace_node_text("monies", random_monies()); }
//window.onload = function(){ document.getElementById("borrower").focus(); document.getElementById("borrower").select()}
