// Global Variables -----------------------------------------------------------

var g_visibleFeatureGroups = new Array();
var g_visibleFeatureGroupsCookieName = "VisibleFeatureGroups";

// Global Functions -----------------------------------------------------------

function FeatureGroupLoadDefaults()
{
	var groupsCookie = GetCookie(g_visibleFeatureGroupsCookieName, "");
	if(groupsCookie != "")
	{
	    var groups = groupsCookie.split(",");
	    for(var i = 0; i < groups.length; i++)
	    {
		    var controlID = groups[i];
		    ShowFeatureGroup(controlID);
		    g_visibleFeatureGroups[controlID] = true;
	    }
	}
}

function FeatureGroupSelectAll_Click(controlID)
{
    var selectAllAnchor = document.getElementById(controlID + 'SelectAll');
    var selectAll = selectAllAnchor.innerHTML == 'Select All' ? true : false;
    
    var control = document.getElementById(controlID);
    var labelControls = control.getElementsByTagName('label');
    for(var i = 0; i < labelControls.length; i++)
    {
        var checkboxControl = labelControls[i].previousSibling;
        checkboxControl.checked = selectAll;
    }
    
    selectAllAnchor.innerHTML = selectAll ? "Select None" : "Select All";
}

function ShowFeatureGroup(controlID)
{
    var control = document.getElementById(controlID);
    if(!control) return;
    control.style.display = control.style.display == "" ? "none" : "";

    var imageControl = document.getElementById(controlID + 'HeadingIcon');
    imageControl.src = control.style.display == "" ? "/images/headingopen.gif" : "/images/headingclosed.gif";

	return control.style.display == "" ? true : false;
}

function FeatureGroupName_Click(controlID)
{
	var isVisible = ShowFeatureGroup(controlID);
	g_visibleFeatureGroups[controlID] = isVisible;

	var groupsCookie  = "";
	var fNeedComma = false;
	for(var id in g_visibleFeatureGroups)
	{
		if(!id || id == "" || !g_visibleFeatureGroups[id]) continue;

		if(fNeedComma) groupsCookie += ",";
		fNeedComma = true;
		groupsCookie += id;
	}

	SetCookie(g_visibleFeatureGroupsCookieName, groupsCookie);
}
