function changeStates( action )
{
	var a = document.getElementsByTagName( 'div' );
	for( var i = 0; i< a.length; i++)
	{
		if( a[i].getAttribute('class') ) {
			if(a[i].getAttribute('class') == 'statecodes') {
				a[i].style.display = action;
			}
		}
		else {
			if( a[i].className == 'statecodes' ) {
				a[i].style.display = action;
			}
		}
	}
	var b = document.getElementsByTagName('h3');
	for( var i = 0; i< b.length; i++)
	{
		b[i].style.display = action;
	}
	setViewAll( action );
}
function setViewAll( action )
{
	var z = document.getElementById("viewAll");
	z.style.cursor = "pointer";
	z.style.textDecoration = "underline";
	z.style.display = "block";

	if( action == "none" )
	{
		z.onclick = function(){ showAll() };
		z.innerHTML = "Show All Codes";
	}
	if( action == "block" )
	{
		z.innerHTML = "Hide All Codes";
		z.onclick = function(){ hideAll() };
	};
}
function  hideStates()
{
	changeStates("none")
	d = document.getElementById('libraryTable');
	var c = d.getElementsByTagName('a');
	for( var i = 0; i< c.length; i++)
	{
		c[i].onclick = function(){ showCity( this ) };
	}
	var e = document.getElementsByTagName('area');
	for( var i = 0; i< e.length; i++)
	{
		e[i].onclick = function(){ showCity( this ) };
		e[i].onmouseover = function(){ updateLink( this, "on" ) };
		e[i].onmouseout = function(){ updateLink( this, "off" ) };
	}
}
function showAll()
{
	changeStates("block");
}
function hideAll()
{
	changeStates("none");
}
function showCity( source)
{

	s = matchAltLink( source, "h3")
	var myItems = s.nextSibling;
	while( myItems.nodeType != "1" )
	{
		myItems = myItems.nextSibling;
	}	
	if ( myItems.style.display == "none" )
	{
		changeStates("none");
		myItems.style.display = "block";
		s.style.display = "block";
	}
	else{
		changeStates("none");
	}
}

function matchAltLink( source, tag )
{
	var s;
	if( source.innerHTML != "" ) {
		s = source.innerHTML;
	}
	else
	{
		s = source.getAttribute('alt');
	}
	var t;
	var b = document.getElementsByTagName(tag);
	for( var i = 0; i < b.length; i++)
	{
		if( b[i].innerHTML == s)
		{
			t = b[i];
		}
	}
	return t;
}
function updateLink ( source , action )
{
	var t = matchAltLink( source, "a" );
	
	if( action == "on" )
	{
		t.className = "hover";
	}
	if( action == "off")
	{
		t.className = "";
	}
}