var maxImageWidth = 600;

function switchforum(x)
{
	if(x.options[x.selectedIndex].value != '')
	{
		if(x.options[x.selectedIndex].id == 'switchCat')
			this.location.href = board_script_url +'/list_category/'+ x.options[x.selectedIndex].value;
		else
			this.location.href = board_script_url +'/list_topics/' + x.options[x.selectedIndex].value;
	}
}

function switchdestinationforum(x)
{
	if(x.options[x.selectedIndex].id == 'switchCat')
		x.selectedIndex = x.selectedIndex + 1;
}

function switchpage(x,topicid,keywords)
{
	this.location.href = board_script_url +'/list_messages/'+topicid+'/' + x.options[x.selectedIndex].value + (keywords != 'undefined' && keywords != '' ? '' : '//' + keywords);
}

function switchfaqpage(x)
{
	this.location.href = board_script_url +'/faq/' + x.options[x.selectedIndex].value;
}

function switchsearchpage(x)
{
	this.location.href = board_script_url +'/find/result/' + x.options[x.selectedIndex].value;
}

function switchforumpage(x,forumid)
{
	this.location.href = board_script_url +'/list_topics/'+forumid+'/' + x.options[x.selectedIndex].value;
}

function switchtopic(x)
{
	this.location.href = board_script_url +'/list_messages/' + x.options[x.selectedIndex].value;
}

function switchbookmarkpage(x)
{
	this.location.href = board_script_url +'/list_bookmarks/' + x.options[x.selectedIndex].value;
}

function showtopic(topicid)
{
	if(Number(topicid) > 0)
	{
		window.open(board_script_url +'/list_messages/'+topicid,'Topic');
	}
	else
	{
		alert('Het topic id is geen getal of niet ingevuld.');
	}
}

function selectsearchforum(x)
{
	for(i=0;i<x.length;i++)
	{
		if(x.options[i].id == 'switchCat')
		{
			x.options[i].selected = false;
		}
	}
}

function selectmoveforum(x)
{
	if(x.options[x.selectedIndex].id == 'switchCat')
	{
		x.options[x.selectedIndex].selected = false;
	}
}

function selectfavouriteforum(x)
{
	s = 0;

	for(i=0;i<x.length;i++)
	{
		if(x.options[i].id == 'switchCat')
			x.options[i].selected = false;
		if(x.options[i].selected == true)
			s++;
		if(s > 3)
			x.options[i].selected = false
	}
}

function bookmarkCheck(checkbox)
{
	var form = checkbox.form;
	var all_checked = true;

	for ( var t = 0; t < form.elements.length; t++ )
	{
		if ( form.elements[t].type == 'checkbox' && !form.elements[t].checked && form.elements[t].name != 'checkem' )
			all_checked = false;
		if ( form.elements[t].name == 'checkem' )
		{
			form.elements[t].checked = all_checked;
			break;
		}
	}
}

function checkEmAll(checkbox)
{
	var form = checkbox.form;

	for ( var t = 0; t < form.elements.length; t++ )
	{
		if ( form.elements[t].type == 'checkbox' && form.elements[t].name != 'checkem' )
			form.elements[t].checked = checkbox.checked;
	}
}

function quote(tring)
{
	var target = document.getElementById( "messageBox" );
	target.value += tring ;
}

function q()
{
	return String.fromCharCode(34);
}

function bookmark_dialog(form)
{
	string = prompt("Onder welke titel wilt u de bookmark bewaren?",form['data[name]'].value);
	if(string == null)
	{
		return false;
	}
	if(string == '')
	{
		alert("U heeft geen titel opgegeven.");
		return false;
	}
	else
	{
		form['data[name]'].value = string;
		return true;
	}
}

var supportsKeys = false

function calcCharLeft_Extended(f,maxLength,s)
{
	charleft = maxLength;
	for(i=count=0;i<f.elements[s].value.length;i++)
	{
		x = f.elements[s].value.charAt(i);

		if(x == '&')
			count += 5;
		else if(x == '"' || x == "'")
			count += 6;
		else if(x == '<' || x == '>')
			count += 4;
		else if(x != '')
			count += 1;

		charleft = maxLength - count;

		if(count > maxLength)
		{
			f.elements[s].value = f.elements[s].value.substring(0,i);

		    f.charsleft.value = charleft;
		    return true;
		}
	}

    f.charsleft.value = charleft;
    return false;
}

function textKey_Extended(f,maxLength,s)
{
	supportsKeys = true;
	calcCharLeft_Extended(f,maxLength,s);
}

function unscaleImage()
{
	if(maxImageWidth > 0)
		this.width = this.width == maxImageWidth? this.orgwidth:maxImageWidth;
}

function scaleImage(im)
{
	if (maxImageWidth > 0 && im.width > maxImageWidth)
	{
		im.orgwidth = im.width;
		im.width = maxImageWidth;
		im.onclick = unscaleImage;
	}
}