function toggleLanguage(id)
{
	var o = obj(id);
	if(!o) return;
	if(o.className == "ShowProductFiles") toggleFiles(id);
	o.className = (o.className == "HideProductInfo")? "ShowProducLanguages": "HideProductInfo";
}

function toggleFiles(id)
{
	var o = obj(id);
	if(!o) return;
	if(o.className == "ShowProducLanguages") toggleLanguage(id);
	o.className = (o.className == "HideProductInfo")? "ShowProductFiles": "HideProductInfo";
}

function obj(id)
{
	return document.getElementById(id);
}

var firstPageImages;
var currentImage=-1;
var imageSwitchTimeout = 7500;
function switchFirstPageImages(arr)
{
	firstPageImages=arr;
	var o=obj("FirstPageBottomImage");
	if(o)
	{
		o.style.visibility="visible";
		rotateFirstPageImages();
	}
}

function rotateFirstPageImages()
{
	var o=obj("FirstPageBottomImage");
	if(!o) return;

	var index=currentImage;
	while(index==currentImage)
	{
		index=Math.floor(Math.random()*firstPageImages.length);
	}
	
	o.src=firstPageImages[index];
	currentImage=index;
	setTimeout("rotateFirstPageImages()", imageSwitchTimeout);
}


function fetchNodesWithAttribute(parent, tagName, attributeName, attributeValue, list)
{
	for(var i = 0; i < parent.childNodes.length; i++)
	{
		var child = parent.childNodes[i];
		if(child.tagName == tagName)
		{
			var attr = child.getAttribute(attributeName);
			if (attr == attributeValue)
			{
				list[list.length] = child
			}
		}
		fetchNodesWithAttribute(child, tagName, attributeName, attributeValue, list);
	}
}

function toggleNode(id)
{
	var o=obj(id);
	if(o)
	{
		o.style.display=(o.style.display=="block")?"none":"block";
	}
}

function setSelectionTexts(l)
{
	for(var r=0;r<l.length;r++)
	{
		var container=obj(l[r]);
		var selection=obj(l[r]+"_selected");
		if(container&&selection)
		{
			var list = [];
			fetchNodesWithAttribute(container, "INPUT", "type", "checkbox", list);
			var selText="";
			for(var i=0;i<list.length;i++)
			{
				if(list[i].checked)
				{
					if(list[i].nextSibling)
					{
						selText+=", "+list[i].nextSibling.innerHTML;
					}
				}
			}
			if(selText.length>0)
			{
				selText=selText.substring(2);
			}
			selection.innerHTML = selText;
		}
	}
}

function checkListBoxSelection(o,id)
{
	var container=obj(id);
	var selection=obj(id+"_selected");
	if(container&&selection)
	{
		var list = [];
		fetchNodesWithAttribute(container, "INPUT", "type", "checkbox", list);
		if(list.length > 1)
		{
			if(o.id==list[0].id) //Check if it's the "All" checkbox that are clicked.
			{
				for(var i=1;i<list.length;i++)
				{
					list[i].checked=false;
				}
				list[0].checked=true;
			}
			else
			{
				list[0].checked=false;
			}
		}
		var selText="";
		for(var i=0;i<list.length;i++)
		{
			if(list[i].checked)
			{
				if(list[i].nextSibling)
				{
					selText+=", "+list[i].nextSibling.innerHTML;
				}
			}
		}
		if(selText.length>0)
		{
			selText=selText.substring(2);
		}
		selection.innerHTML = selText;
	}
}

function toggleTags()
{
	var o=obj('SearchResultDiv');
	if(o){
		o.className=(o.className=='HideTags')?'ShowTags':'HideTags';
	}
}


