function klappe(id)
{
	var klappText = document.getElementById('k' + id);

	if (klappText.style.display == 'none') {
	 klappText.style.display = 'block';
	}
	else {
	 klappText.style.display = 'none';
	}
}

function klappe_news(id)
{
	var klappText = document.getElementById('k' + id);
	var klappBild = document.getElementById('pic' + id);

	if (klappText.style.display == 'none') {
	 klappText.style.display = 'block';
	 klappBild.src = 'pic/minus.gif';
	}
	else {
	 klappText.style.display = 'none';
	 klappBild.src = 'pic/plus.gif';
	}
}

function Post()
{
	document.compose.action = "?action=post"
	document.compose.target = "";
	document.compose.submit();
	return true;
}

function Preview()
{
	document.compose.action = "?action=preview"
	document.compose.target = "";
	document.compose.submit();
	return true;
}

function togglediv(id)
{
	if (document.getElementById)
	{
		aref = document.getElementById("a"+id);
		if (aref.innerHTML == "Click here to expand")
			aref.innerHTML = "Click here to contract";
		else if (aref.innerHTML == "Click here to contract")
			aref.innerHTML = "Click here to expand";
		img = document.getElementById("i"+id);
		img.src = (img.src.match("pic/plus.gif") == null ? "pic/plus.gif" : "pic/minus.gif");
		vis = document.getElementById("d"+id).style;
		vis.display = (vis.display == "block" ? "none" : "block");
	}
}

// Taken from bittorrent.php somewhere in 2007, marks/unmarks all checkboxes.
var checkflag = "false";
function check(field)
{
	if (checkflag == "false")
	{
		for (i = 0; i < field.length; i++)
		{
			field[i].checked = true;
		}
		checkflag = "true";
		return "Uncheck All";
	}
	else
	{
		for (i = 0; i < field.length; i++)
		{
			field[i].checked = false;
		}
		checkflag = "false";
		return "Check All";
	}
}

function doClear() {
	document.forms['shbox']['shbox_text'].value = ""
}

function showhide(placeholder, url) {
	//Make sure the browser is DOM compliant
	if (!document.getElementById) {
		//Allow the hyperlink to process normally
		return true;
	}
	//Get the placeholder div
	var ph = document.getElementById(placeholder);
	if (ph.innerHTML != "")	{
		//The div has content; just toggle its display
		ph.style.display = (ph.style.display == "none" ? "block" : "none");
	}
	else {
		//The div is empty; use AJAX to populate it with the contents from url
		//Initialize AJAX
		var xmlHttp;
		// Firefox, Opera 8.0+, Safari
		if (window.XMLHttpRequest) {
			xmlHttp = new XMLHttpRequest();
		}
		// Internet Explorer
		else if (window.ActiveXObject) {
			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		}

		if (xmlHttp == null) {
			ph.innerHTML = "Your browser does not support AJAX.";
			//Allow the hyperlink to process normally
			return true;
		}

		//Remove any pre-existing data
		ph.innerHTML = "Loading...<br /><img src=\'ajax/loading.gif\' />";

		xmlHttp.onreadystatechange = function() {
			if(xmlHttp.readyState==4) {
				ph.innerHTML = xmlHttp.responseText;
			}
		}
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
	}
	//Prevent the anchor href from being called
	return false;
}

function karmavote(placeholder, url) {
	//Make sure the browser is DOM compliant
	if (!document.getElementById) {
		//Allow the hyperlink to process normally
		return true;
	}

	//Get the placeholder div
	var ph = document.getElementById(placeholder);

	//Initialize AJAX
	var xmlHttp;
	// Firefox, Opera 8.0+, Safari
	if (window.XMLHttpRequest) {
		xmlHttp = new XMLHttpRequest();
	}
	// Internet Explorer
	else if (window.ActiveXObject) {
		xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	}

	if (xmlHttp == null) {
		ph.innerHTML = "Your browser does not support AJAX.";
		//Allow the hyperlink to process normally
		return true;
	}

	//disable buttons
	function findButton (button) {
		while (button.nodeType !== 1 || button.tagName &&
			 !(button.tagName.toLowerCase() !== 'img' ||
				 button.tagName.toLowerCase() !== 'a'))
			button = button.previousSibling
		return button
	}

	var negative = ph.lastChild;
	negative = findButton(negative)

	var positive = negative.previousSibling
	positive = findButton(positive)

	function disableButton (button) {
		var child, realButton = button,
			regexp = /(plus|minus)\./;
		if (button.tagName.toLowerCase() === 'a') {
			while (child = button.firstChild) {
				if (child.tagName.toLowerCase() === 'img')
					realButton = child
				button.parentNode.insertBefore(child, button)
			}
			button.parentNode.removeChild(button)
		}
		realButton.src = realButton.src.replace(regexp, '$1_inop.')
	}

	disableButton(negative)
	disableButton(positive)

	xmlHttp.onreadystatechange = function() {
		if(xmlHttp.readyState==4) {
			ph.innerHTML = xmlHttp.responseText;
		}
	}
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);

	//Prevent the anchor href from being called
	return false;
}

function searchInputToggle (input) {
	input.helpText = input.helpText ? input.helpText : input.value
	if (input.value == '')
		input.value = input.helpText
	else if (input.value == input.helpText)
		input.value = ''
}

// For sitelog links
function getlinks()
{
	var slRows = document.getElementById('tblSiteLog').getElementsByTagName('tr');
	var slCell;
	for (var i = 1; i < slRows.length; i++)
	{
		slCell = slRows[i ].getElementsByTagName('td')[2].getElementsByTagName('span')[0];
		slCell.innerHTML = slCell.innerHTML.replace(/^(Torrent) ([0-9]+)/,"<a href=/sitelog.php?search=%22$1+$2%22>$&</a>").replace(/\w+$/,"<a href=/sitelog.php?search=%22$&%22>$&</a>");
	}
}