//selects an option from the specified select element
function select_option( element, id )
{
	if( document.getElementById(element) )
	{
		var select = document.getElementById(element);
		var loop = true;
		for( i=0; i<select.length && loop; i++ )
		{
			if( select.options[i].value == id )
			{
				select.selectedIndex = i;
				loop = false;
			}
		}
	}
}
// real-time countdown of characters entered allowed into a textarea element -- use with onkeyup event
function update_char_count( text, maxlength, counter) 
{
	document.getElementById(counter).value = text.length > 0 ? maxlength - text.length : maxlength;
}
// restrictes a textarea element to the specified size -- use with onkeypress event
function maxlength( e, text, maxlength )
{
	if(window.event) // IE
		keynum = e.keyCode;
	else if(e.which) // Netscape/Firefox/Opera
		keynum = e.which;
		
	if( keynum >= 32 && keynum <= 127 && text.length >= maxlength )
		return false;
	else
		return true;
}
//contols for collapable divs used in the census info (state and town pages)
function census_control(o)
{
	//alert(document.getElementById(o).style.display);
	if( document.getElementById(o+'_control') && document.getElementById(o) )
	{
		if( document.getElementById(o+'_control').innerHTML == '[-]')
		{
			document.getElementById(o).style.display = 'none';
			document.getElementById(o+'_control').innerHTML = '[+]';
		}
		else
		{
			document.getElementById(o).style.display = 'block';
			document.getElementById(o+'_control').innerHTML = '[-]';
		}
	}
	return false;
}
function goto_town(state,url)
{
	if( url != "-1" && url != 'false' && url != false)
		document.location.href=state+url;
}
function goto_url(url)
{
		document.location.href=url;
}