
function getHTTPObject() 
{
	var requester;

	try 
	{ 
		requester = new XMLHttpRequest(); 
	} 
	catch (error) 
	{ 
		try 
		{ 
			requester = new ActiveXObject("Microsoft.XMLHTTP"); 
		} 
		catch (error) 
		{ 
			requester = false; 
		}
	}
	
	return requester;
}

function collapse(root)
{
	var nextSibling = getNextSibling(root);

	while (nextSibling != null)
	{
		if (nextSibling.className == "location")
			return;

		if (nextSibling.className == root.className)
			return;

		nextSibling.style.display = "none";
		nextSibling = getNextSibling(nextSibling);
	}				
}

function getNextSibling(startBrother)
{
    endBrother = startBrother.nextSibling;
    
    while (endBrother != null && endBrother.nodeType != 1)
    {
        endBrother = endBrother.nextSibling;
    }
    
    return endBrother;
}

function getCollectionIMGNode(root)
{
   var node = root;

   while (1)
   {
       node = node.firstChild;
       while (node != null && node.nodeName == "#text" || (node.nodeName == "IMG" && node.src.search("plus") == -1  && node.src.search("minus") == -1 ))
           node = node.nextSibling;
       
       if (node == null)
           break;
       
       if ((node.nodeName == "IMG") && ((node.src.search("plus") != -1 ) || (node.src.search("minus") != -1 )))
           break;
   }   
   
   return node;
}

function expand(root)
{
	var nextSibling = getNextSibling(root); 
	var pieceDisplay = "";

	while (nextSibling != null)
	{
		if (nextSibling.className == root.className)
			return;

		switch (nextSibling.className)
		{
		case "collection":
			nextSibling.style.display = "";
			var img = getCollectionIMGNode(nextSibling);
			if (img != null)
			{
				if (img.src.search("plus") == -1)
					pieceDisplay = "";
				else
					pieceDisplay = "none";								
			}
			break;
		case "piece":
			nextSibling.style.display = pieceDisplay;
			break;
		}

		nextSibling = getNextSibling(nextSibling); //nextSibling.nextSibling;
	}				
}

function doToggle(e, plus, minus, plusAlt, minusAlt)
{	
	var img;
    var element;
    
    if (e.srcElement)
        element = e.srcElement;
    else
        element = e.target;
    
	if (element.className == "group")
	{
		switch (element.nodeName)
		{
		case "A":
			img = element.firstChild;
			break;
		case "IMG":
			img = element;
			break;
		default:
			return;
		}
	}
	else
		return;

	var root = img.parentNode.parentNode.parentNode.parentNode;
	var display;
						
	if (img.src.search("plus") == -1)
	{
		img.src = plus;
		img.alt = plusAlt;
		collapse(root);
	}
	else
	{
		img.src = minus;
		img.alt = minusAlt;
		expand(root);
	}
}


