/*
	NOTE: 20 april 2010 - When <%includelist%> is updated, change the url to get SEO-title / RAT
*/


var selectedSearchType = null;

function initSearchTypes() {
	
	searchtypes = document.getElementById('search-types').getElementsByTagName('img');

	for (i=0; i<searchtypes.length; i++) 
	{                   
		node = searchtypes[i];
		
		node.onmouseover=function() {
			this.src = this.src.replace(/-out./,"-over.");
		}
		
		node.onmouseout=function() {
			if(this.id != selectedSearchType)					
				this.src = this.src.replace(/-over./,"-out.");
		}
		
		node.onclick=function() {
			ShowList(this.id);			
			setSelectedSearchType(this.id);
		}
	}	
	
	SortLists();
}

function setSelectedSearchType(category)
{			
	if( (category != null) && (selectedSearchType == category) )
	{
		document.getElementById(category).src = document.getElementById(category).src.replace(/-over./,"-out.");
		selectedSearchType = null;
		document.forms['search-form'].reset();
		ShowList('both');
	}
	else if( (category != null) && (selectedSearchType == null) )
	{
		document.getElementById(category).src = document.getElementById(category).src.replace(/-out./,"-over.");
		selectedSearchType = category;
		document.forms['search-form'].reset();
	}
	else if( (category == null) && (selectedSearchType != null) )
	{
		document.getElementById(selectedSearchType).src = document.getElementById(selectedSearchType).src.replace(/-over./,"-out.");
		selectedSearchType = category;
		document.forms['search-form'].reset();
	}
	else if( (category != null) && (selectedSearchType != null) )
	{
		document.getElementById(selectedSearchType).src = document.getElementById(selectedSearchType).src.replace(/-over./,"-out.");
		document.getElementById(category).src = document.getElementById(category).src.replace(/-out./,"-over.");
		selectedSearchType = category;
		document.forms['search-form'].reset();
	}
}

function Search(searchword)
{
	setSelectedSearchType(null);

	var tempArray = new Array();

	for(i=0;i<personer.length;i++)
	{
		var searchCondition = new RegExp(searchword,"i");
		if(personer[i][0].search(searchCondition) != -1)
		{
			tempArray.push(personer[i]);
		}
	}
	
	if(tempArray.length==0)
		tempArray.push(new Array('','Ingen match funnet'));
	
	ShowList(tempArray);

	return false;
}		

function ShowList(category)
{
	var targetArea = document.getElementById('list');
	var targetList = new Array();

	switch(category)
	{
		case 'underholdning' :
		{
			targetList = underholdning;
			break;
		}

		case 'foredrag' :
		{
			targetList = foredrag;
			break;
		}
		case 'both' :
		{
			targetList = personer;					
			break;
		}
		
		default :
		{
			targetList = category;
			break;
		}
	}

	var list = "";
	
	for(i=0;i<targetList.length;i++)
	{
		 list += '<li>';
		
		 if(targetList[i][1]!='')
			list += '<a href="http://www.seminarpartner.no/'+targetList[i][1]+'">'+targetList[i][0]+'</a>';
		 else
			list += targetList[i][0];
			
		 list += '</li>';
	}

	targetArea.innerHTML = "<ul>"+list+"</ul>";
}

function SortLists()
{
	underholdning = underholdning.sort();
	foredrag = foredrag.sort();
}


function CheckImage(PictureID)
{
	if(PictureID)
		document.write('<img src="../../images/'+PictureID+'" alt="" />');
	else
		return;
}
