var registeredSection = new Array();


/*
	Initalizes all of the registered section arrays for however many sections are desired
	Usage: initSection(3);
	Registers 3 sections (0..2)
*/
function initSections(numSections)
{
	for (i=0; i<numSections; i++)
	{
		registeredSection[i] = new Array();
	}
}

/*
	Registers an itemId as a memeber of a given section
	Usage: registerItem(2, "news_story_23");
	Sets the item with id "news_story_23" to be a member of section 2
*/
function registerItem(sectionId, itemId)
{
	registeredSection[sectionId][registeredSection[sectionId].length] = itemId;
}

/*
	Registers a list of itemId's as members of a given section
	Usage: registerItems(2, "news_story_23,news_story_17,news_story_72");
	Sets the items with ids "news_story_23", "news_story_17" and "news_story_72" to be members of section 2
*/
function registerItems(sectionId, itemList)
{
	if (typeof itemList == "string")
	{
		itemList = itemList.split(",");
	}
	for (i=0; i<itemList.length; i++)
	{
		registerItem(sectionId, itemList[i]);
	}
}

/*
	Sets the display for all registered items in a section
	Usage: setItemDisplay(2, "block");
	Sets all items registered for section 2 to "display:block"
*/
function setItemDisplay(sectionId, displayType)
{
	for (i=0; i<registeredSection[sectionId].length; i++)
	{
		itemId = registeredSection[sectionId][i];
		document.getElementById(itemId).style.display = displayType;
	}
}

function setAllItems(displayType)
{
	for (j=0; j<registeredSection.length; j++)
	{
		setItemDisplay(j, displayType);
	}
}

function setAllItemsOn()
{
	setAllItems("block");
}

function setAllItemsOff()
{
	setAllItems("none");
}

function toggleItemDisplay(sectionId)
{
	if (document.getElementById(registeredSection[sectionId][0])) {
		currentDisplay = document.getElementById(registeredSection[sectionId][0]).style.display;
		if (currentDisplay == "block")
		{
			setItemDisplay(sectionId, "none");
		}
		else {
			setItemDisplay(sectionId, "block");
		}
	}
}

/*
	Generate a list of all ids stored for a given section
*/
function debugRegisteredSection(sectionId)
{
	result="";
	for (i=0; i<registeredSection[sectionId].length; i++)
	{
		result=result+"["+i+"]=\""+registeredSection[sectionId][i]+"\" ";
	}
	return result;
}

/*
	Generate the complete registeredSection array in printable form.
*/
function debugRegisteredSections()
{
	mainresult="";
	for (j=0; j<registeredSection.length; j++)
	{
		mainresult=mainresult+"Section: "+j+" = "+debugRegisteredSection(j)+"<br>\n";
	}
	return mainresult;
}

function debugDisplay(typeOfDisplay)
{
	if (typeOfDisplay=="write")
	{
		document.write(debugRegisteredSections());
	}
	else
	{
		window.alert(debugRegisteredSections());
	}
}