/*
	IOSPIRIT Tools
	(C) 2009 by IOSPIRIT GmbH, Felix Schwarz
	All rights reserved.
	
	DO NOT COPY THIS SCRIPT OR USE IT ON YOUR WEBSITE.	
	THIS SCRIPT MAY NOT BE USED AT ANY WEBSITE OTHER THAN THE IOSPIRIT WEBSITE.
*/

function FilterBoxChange(obj, newValue, matchWithAttributeOfName)
{
	var i, liNodes, filterNodes, filterValue, adaptNodeAttributeName, nodeVisibilityAttributeName;

	adaptNodeAttributeName 	    = 'adaptnode';
	nodeVisibilityAttributeName = 'ismatching';

	if (typeof(matchWithAttributeOfName) == 'undefined')
	{
		matchWithAttributeOfName = "matchfilterkeywords";
	}

	liNodes = obj.parentNode.parentNode.childNodes;
	
	if (liNodes.length)
	{
		for (i=0; i<liNodes.length; i++)
		{
			if (liNodes[i].childNodes.length != 0)
			{
				liNodes[i].childNodes[0].className = "";
			}
		}
	}
	
	obj.className = "selected";
	obj.parentNode.parentNode.setAttribute("filterValue", newValue);
	
	// Compile keyword list
	filterKeywords = new Array();

	if (filterNodes = obj.parentNode.parentNode.parentNode.childNodes)
	{
		for (i=0; i<filterNodes.length; i++)
		{
			if (filterNodes[i].tagName == "OL")
			{
				if (filterValue = filterNodes[i].getAttribute("filterValue"))
				{
					if (filterValue != "all")
					{
						filterKeywords.push(filterValue);
					}
				}
			}
		}
	}
	
	// Perform filtering
	filterDivs = document.getElementsByTagName('div');
	
	for (i=0;i<filterDivs.length;i++)
	{
		if (filterDivs[i].getAttribute(matchWithAttributeOfName))
		{
			var matches=0, matchFilterKeywordsString, controlNodeWithId, controlNodeObj;
			
			if (matchFilterKeywordsString = filterDivs[i].getAttribute(matchWithAttributeOfName))
			{
				var filterIterator, matchIterator, matchFilterKeywords;
			
				matchFilterKeywords = matchFilterKeywordsString.split(",");
			
				for (filterIterator=0; filterIterator<filterKeywords.length; filterIterator++)
				{
					for (matchIterator=0; matchIterator<matchFilterKeywords.length; matchIterator++)
					{
						if (matchFilterKeywords[matchIterator] == filterKeywords[filterIterator])
						{
							matches++;
							break;
						}
					}
				}
			}
			
			controlNodeObj = 0;

			if (controlNodeWithId = filterDivs[i].getAttribute(adaptNodeAttributeName))
			{
				controlNodeObj = document.getElementById(controlNodeWithId);
			}
			
			if (matches == filterKeywords.length)
			{
				filterDivs[i].style.display = "block";
				if (controlNodeObj)
				{
					controlNodeObj.setAttribute(nodeVisibilityAttributeName, "yes");
				}
			}
			else
			{
				filterDivs[i].style.display = "none";
				if (controlNodeObj)
				{
					controlNodeObj.setAttribute(nodeVisibilityAttributeName, "no");
				}
			}
		}
	}
	
	return (false);
}