function formatCurrency (num) 
{
	num = num.toString().replace(/\$|\,/g,'');
	
	if(isNaN(num))
	{
		num = "0";
	}

	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num*100+0.50000000001);
	cents = num%100;
	num = Math.floor(num/100).toString();
	
	if(cents<10)
	{
		cents = "0" + cents;
	}
	
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
	{
		num = num.substring(0,num.length-(4*i+3))+','+ num.substring(num.length-(4*i+3));
	}
	
	return (((sign)?'':'-') + '$' + num + '.' + cents);
}

function formatDate (date)
{
	return date;
}

function arraySearch (searchS, arraySA) 
{
	var I = 0;
	var minI = 0;
	var maxI = arraySA.length - 1;
	var s = "";
	var foundB = false;
	I = minI - 1;
	
	while ( ( I <= maxI ) && ( !( foundB ) ) ) 
	{
		I = I + 1;
		s = arraySA[ I ];
		foundB = ( searchS == s );
	}
	
	if ( foundB ) 
	{
		return( I );
	}
	else 
	{
		return(false); // some negative number indicating not found
	}
}

function getElementsByClass (searchClass, node, tag) 
{
	var classElements = new Array();
	
	if (node == null)
	{
		node = document;
	}
	
	if (tag == null)
	{
		tag = '*';
	}
	
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
	
	for (i = 0, j = 0; i < elsLen; i++) 
	{
		if (pattern.test(els[i].className)) 
		{
			classElements[j] = els[i];
			j++;
		}
	}
	
	return classElements;
}

function toggleSticky(img_id, popup_id)
{
	img_element = document.getElementById(img_id);
	popup_element = document.getElementById(popup_id);

	if (img_element.src.search("pushpin_in.jpg") >= 0)
	{
		img_element.src = "/images/pushpin_out.jpg"
		popup_element.onmouseout = function() { timeout_handles[popup_id] = setTimeout('toggleDisplay(\''+popup_id+'\',\'none\');', timeout); }
	}
	else
	{
		img_element.src = "/images/pushpin_in.jpg"
		popup_element.onmouseout = function() { return true; }
	}
}

function toggleDisplay(id, force)
{
	element = document.getElementById(id);

	if (force == false)
	{
		if (element.style.display == "block")
		{
			element.style.display = "none";
		}
		else
		{
			element.style.display = "block";
		}
	}
	else
	{
		element.style.display = force;
	}
}

// popup_id is the id of the element to be shown/hidden.
// link_id is the id of the link which manually shows/hides it.
var timeout_handles = new Array();
var timeout = 500;		// the 'natural' part

function addNaturalPopUp(link_id, popup_id)
{
	var popup_element = document.getElementById(popup_id);
	popup_element.onmouseover = function() { clearTimeout(timeout_handles[popup_id]); }
	popup_element.onmouseout = function() { timeout_handles[popup_id] = setTimeout('toggleDisplay(\''+popup_id+'\',\'none\');', timeout); }

	var link_element = document.getElementById(link_id);
	link_element.href = "javascript:toggleDisplay('"+popup_id+"',false);"
	link_element.onmouseout = function() { clearTimeout(timeout_handles[popup_id]); document.getElementById(popup_id).onmouseout(); }
	link_element.style.cursor = "pointer";
}