
function FilterSubHeading_ToggleItems(div, baseUrl)
{
    // because nextSibling can return whitespace or text, 
    // we'll loop until we find the real nextSibling.
    var items = div;            
    do items = items.nextSibling; 
    while (items && items.nodeType != 1);
    
    var arrow = div.getElementsByTagName("img")[0];
    
    if(items.style.display == "none") items.style.display = "block";
    else items.style.display = "none";
    
    if(arrow.src.indexOf("down") > -1) arrow.src = baseUrl + "/images/arrow-up.gif";
    else arrow.src = baseUrl + "/images/arrow-down.gif";            
}   

function ToggleStates(e, stateId, imageId, baseUrl)
{
    // get states div...
    var divStates = document.getElementById(stateId);
    
    // get arrow image
    var imgArrow = document.getElementById(imageId);
    
    // toggle away!
    if(divStates.className.indexOf("hidden_states") != -1)
    {
       divStates.className = "states" // show
       imgArrow.src =  baseUrl + "/images/arrow-up-white.gif";
    }
    else
    {
       divStates.className = "states hidden_states" // hide
       imgArrow.src =  baseUrl + "/images/arrow-down-white.gif";
    }
}   

function SelectAllStatesByRegion(e, stateId, checkboxId, imageId)
{
    // get states div
    var divStates = document.getElementById(stateId);
 
    // get arrow image
    var imgArrow = document.getElementById(imageId);
    
    // get checkbox region
    var chkRegion = document.getElementById(checkboxId);
 
    // get the checkboxes   
    var checkboxes = divStates.getElementsByTagName("input");
    
    // loop thru and check the specified checkboxes        
    for (i = 0; i < checkboxes.length; i++)
        checkboxes[i].checked = chkRegion.checked;

	if ( chkRegion.checked )
	{
		if ( divStates.className.indexOf("hidden_states") != -1 )
		{
			divStates.className = "states" // show

			if ( imgArrow.src.indexOf( "-down-" ) != -1 )
				imgArrow.src = imgArrow.src.replace( "-down-", "-up-" );
		}
	}

	//	prevent the outer click event from firing

	if ( !e ) var e = window.event;

	e.cancelBubble = true;

	if ( e.stopPropagation )
		e.stopPropagation();
}


function stateClicked( panelId, masterCheckId, arrowId, checkboxId, areaId )
{
	var checkbox = document.getElementById( checkboxId );
	var panel = document.getElementById( panelId );
	var masterCheck = document.getElementById( masterCheckId );
	var arrow = document.getElementById( arrowId );
	var area = document.getElementById( areaId );
	var	box, checkboxes, checkid, nchecked, nunchecked;
	var i;

	//	toggle the checkbox

	checkbox.checked = !checkbox.checked;

	//	see how many boxes are checked in this region. if 0,
	//	collapse the region, otherwise, expand it.

	checkboxes = panel.getElementsByTagName("input");
	
	nchecked = 0;
	nunchecked = 0
	
	for ( i = 0; i < checkboxes.length; ++i )
	{
		if ( checkboxes[i].checked )
				++nchecked;
			else
				++nunchecked;
	}

	if ( nchecked > 0 )
	{
		panel.className = "states";
		if ( arrow.src.indexOf( "-down-" ) != -1 )
			arrow.src = arrow.src.replace( "-down-", "-up-" );
	}
//	else
//	{
//		panel.className = "states hidden_states";
//		if ( arrow.src.indexOf( "-up-" ) != -1 )
//			arrow.src = arrow.src.replace( "-up-", "-down-" );
//	}

	//	finally, set the state of the "master" checkbox. if *all* states
	//	in the region are checked, the master box will also, otherwise
	//	it will be cleared.

	masterCheck.checked = (nunchecked == 0);
}


// Sets the src attribute of the image object passed.
function SwapNavImage(obj, Image)
{
    
    obj.src = Image;
}

// Sets the class attribute of the object passed.
function SwapClass(obj, NewClass)
{   
    obj.style.className = NewClass;
}

function ToggleAllCheckboxes(container, masterCheckbox)
{
    // get the location div
    var divLocations = document.getElementById(container);
        
    // get the checkboxes   
    var checkboxes = divLocations.getElementsByTagName("input");
    
    // loop thru and check the specified checkboxes        
    for (i = 0; i < checkboxes.length; i++)
        checkboxes[i].checked = masterCheckbox.checked;
}

